Here are the examples of the csharp api System.Threading.Tasks.Task.FromResult(string) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1190 Examples
19
View Source File : MethodInvokerTest.cs
License : MIT License
Project Creator : 1100100
License : MIT License
Project Creator : 1100100
public async Task<string> GetString()
{
return await Task.FromResult("test string");
}
19
View Source File : Startup.cs
License : MIT License
Project Creator : 2881099
License : MIT License
Project Creator : 2881099
[Custom]
public virtual async Task CreateKeyAsync(CustomDto customDto)
{
await Task.FromResult("");
Console.WriteLine($"CustomRepository.CreateAsync({customDto.Key}) value");
}
19
View Source File : CodeGenerate.cs
License : MIT License
Project Creator : 2881099
License : MIT License
Project Creator : 2881099
public async Task<string> Setup(TaskBuild taskBuild, string code, List<DbTableInfo> dbTables, DbTableInfo dbTableInfo)
{
StringBuilder plus = new StringBuilder();
try
{
var config = new TemplateServiceConfiguration();
config.EncodedStringFactory = new RawStringFactory();
Engine.Razor = RazorEngineService.Create(config);
var razorId = Guid.NewGuid().ToString("N");
Engine.Razor.Compile(code, razorId);
var sw = new StringWriter();
var model = new RazorModel(taskBuild, dbTables, dbTableInfo);
Engine.Razor.Run(razorId, sw, null, model);
plus.AppendLine("//------------------------------------------------------------------------------");
plus.AppendLine("// <auto-generated>");
plus.AppendLine("// 此代码由工具生成。");
plus.AppendLine("// 运行时版本:" + Environment.Version.ToString());
plus.AppendLine("// Website: http://www.freesql.net");
plus.AppendLine("// 对此文件的更改可能会导致不正确的行为,并且如果");
plus.AppendLine("// 重新生成代码,这些更改将会丢失。");
plus.AppendLine("// </auto-generated>");
plus.AppendLine("//------------------------------------------------------------------------------");
plus.Append(sw.ToString());
plus.AppendLine();
return await Task.FromResult(plus.ToString());
}
catch
{
return await Task.FromResult(plus.ToString());
}
}
19
View Source File : TrainTrainSystemShould.cs
License : MIT License
Project Creator : 42skillz
License : MIT License
Project Creator : 42skillz
private static IBookingReferenceService BuildBookingReferenceService(string bookingReference)
{
var bookingReferenceService = Subsreplacedute.For<IBookingReferenceService>();
bookingReferenceService.GetBookingReference().Returns(Task.FromResult(bookingReference));
return bookingReferenceService;
}
19
View Source File : TrainTrainSystemShould.cs
License : MIT License
Project Creator : 42skillz
License : MIT License
Project Creator : 42skillz
private static ITrainDataService BuildTrainDataService(string trainId, string trainTopology)
{
var trainDataService = Subsreplacedute.For<ITrainDataService>();
trainDataService.GetTrain(trainId)
.Returns(Task.FromResult(trainTopology));
return trainDataService;
}
19
View Source File : ConstantRemotePathProvider.cs
License : MIT License
Project Creator : Accelerider
License : MIT License
Project Creator : Accelerider
public virtual Task<string> GetAsync()
{
if (RemotePaths.Values.All(item => item < 0))
throw new RemotePathExhaustedException(this);
return Task.FromResult(
RemotePaths.Aggregate((acc, item) => acc.Value < item.Value ? item : acc).Key);
}
19
View Source File : StepHost.cs
License : MIT License
Project Creator : actions
License : MIT License
Project Creator : actions
public Task<string> DetermineNodeRuntimeVersion(IExecutionContext executionContext)
{
return Task.FromResult<string>("node12");
}
19
View Source File : ServerDataProvider.cs
License : MIT License
Project Creator : actions
License : MIT License
Project Creator : actions
public Task<String> LocationForAccessMappingAsync(
ServiceDefinition serviceDefinition,
AccessMapping accessMapping,
CancellationToken cancellationToken = default(CancellationToken))
{
ArgumentUtility.CheckForNull(serviceDefinition, "serviceDefinition");
ArgumentUtility.CheckForNull(accessMapping, "accessMapping");
// If this is FullyQualified then look through our location mappings
if (serviceDefinition.RelativeToSetting == RelativeToSetting.FullyQualified)
{
LocationMapping locationMapping = serviceDefinition.GetLocationMapping(accessMapping);
if (locationMapping != null)
{
return Task.FromResult<String>(locationMapping.Location);
}
// We weren't able to find the location for the access mapping. Return null.
return Task.FromResult<String>(null);
}
else
{
// Make sure the AccessMapping has a valid AccessPoint.
if (String.IsNullOrEmpty(accessMapping.AccessPoint))
{
throw new InvalidAccessPointException(WebApiResources.InvalidAccessMappingLocationServiceUrl());
}
String webApplicationRelativeDirectory = m_locationDataCacheManager.WebApplicationRelativeDirectory;
if (accessMapping.VirtualDirectory != null)
{
webApplicationRelativeDirectory = accessMapping.VirtualDirectory;
}
Uri uri = new Uri(accessMapping.AccessPoint);
String properRoot = String.Empty;
switch (serviceDefinition.RelativeToSetting)
{
case RelativeToSetting.Context:
properRoot = PathUtility.Combine(uri.AbsoluteUri, webApplicationRelativeDirectory);
break;
case RelativeToSetting.WebApplication:
properRoot = accessMapping.AccessPoint;
break;
default:
Debug.replacedert(true, "Found an unknown RelativeToSetting");
break;
}
return Task.FromResult<String>(PathUtility.Combine(properRoot, serviceDefinition.RelativePath));
}
}
19
View Source File : ServerDataProvider.cs
License : MIT License
Project Creator : actions
License : MIT License
Project Creator : actions
public Task<String> LocationForAccessMappingAsync(
ServiceDefinition serviceDefinition,
AccessMapping accessMapping,
CancellationToken cancellationToken = default(CancellationToken))
{
ArgumentUtility.CheckForNull(serviceDefinition, "serviceDefinition");
ArgumentUtility.CheckForNull(accessMapping, "accessMapping");
// If this is FullyQualified then look through our location mappings
if (serviceDefinition.RelativeToSetting == RelativeToSetting.FullyQualified)
{
LocationMapping locationMapping = serviceDefinition.GetLocationMapping(accessMapping);
if (locationMapping != null)
{
return Task.FromResult<String>(locationMapping.Location);
}
// We weren't able to find the location for the access mapping. Return null.
return Task.FromResult<String>(null);
}
else
{
// Make sure the AccessMapping has a valid AccessPoint.
if (String.IsNullOrEmpty(accessMapping.AccessPoint))
{
throw new InvalidAccessPointException(WebApiResources.InvalidAccessMappingLocationServiceUrl());
}
String webApplicationRelativeDirectory = m_locationDataCacheManager.WebApplicationRelativeDirectory;
if (accessMapping.VirtualDirectory != null)
{
webApplicationRelativeDirectory = accessMapping.VirtualDirectory;
}
Uri uri = new Uri(accessMapping.AccessPoint);
String properRoot = String.Empty;
switch (serviceDefinition.RelativeToSetting)
{
case RelativeToSetting.Context:
properRoot = PathUtility.Combine(uri.AbsoluteUri, webApplicationRelativeDirectory);
break;
case RelativeToSetting.WebApplication:
properRoot = accessMapping.AccessPoint;
break;
default:
Debug.replacedert(true, "Found an unknown RelativeToSetting");
break;
}
return Task.FromResult<String>(PathUtility.Combine(properRoot, serviceDefinition.RelativePath));
}
}
19
View Source File : FileVideoSourceHandler.cs
License : MIT License
Project Creator : adamfisher
License : MIT License
Project Creator : adamfisher
public Task<string> LoadVideoAsync(VideoSource source, CancellationToken cancellationToken = default(CancellationToken))
{
string path = null;
var fileVideoSource = source as FileVideoSource;
if (!string.IsNullOrEmpty(fileVideoSource?.File) && File.Exists(fileVideoSource.File))
{
path = fileVideoSource.File;
}
return Task.FromResult(path);
}
19
View Source File : UriVideoSourceHandler.cs
License : MIT License
Project Creator : adamfisher
License : MIT License
Project Creator : adamfisher
public async Task<string> LoadVideoAsync(VideoSource source, CancellationToken cancellationToken = default(CancellationToken))
{
string path = null;
var uriVideoSource = source as UriVideoSource;
if (uriVideoSource?.Uri != null)
{
path = uriVideoSource.Uri.AbsoluteUri;
}
return await Task.FromResult(path);
}
19
View Source File : UriVideoSourceHandler.cs
License : MIT License
Project Creator : adamfisher
License : MIT License
Project Creator : adamfisher
public Task<string> LoadVideoAsync(VideoSource source, CancellationToken cancellationToken = default(CancellationToken))
{
string path = null;
var uriVideoSource = source as UriVideoSource;
if (uriVideoSource?.Uri != null)
{
path = uriVideoSource.Uri.AbsoluteUri;
}
return Task.FromResult(path);
}
19
View Source File : FileVideoSourceHandler.cs
License : MIT License
Project Creator : adamfisher
License : MIT License
Project Creator : adamfisher
public Task<string> LoadVideoAsync(VideoSource source, CancellationToken cancellationToken = default(CancellationToken))
{
string path = null;
var fileVideoSource = source as FileVideoSource;
if (!string.IsNullOrEmpty(fileVideoSource?.File))
{
path = fileVideoSource.File;
}
return Task.FromResult(path);
}
19
View Source File : RazorEngineTemplateBase.cs
License : MIT License
Project Creator : adoconnection
License : MIT License
Project Creator : adoconnection
public virtual Task<string> ResultAsync()
{
return Task.FromResult<string>(this.stringBuilder.ToString());
}
19
View Source File : BaseTest.cs
License : MIT License
Project Creator : Adyen
License : MIT License
Project Creator : Adyen
protected Client CreateMockTestClientNullRequiredFieldsRequest(string fileName)
{
var mockPath = GetMockFilePath(fileName);
var response = MockFileToString(mockPath);
//Create a mock interface
var clientInterfaceMock = new Mock<IClient>();
var confMock = MockPaymentData.CreateConfingMock();
clientInterfaceMock.Setup(x => x.Request(It.IsAny<string>(), It.IsAny<string>(), confMock)).Returns(response);
clientInterfaceMock.Setup(x => x.Request(It.IsAny<string>(), It.IsAny<string>(), confMock, It.IsAny<bool>(), It.IsAny<RequestOptions>())).Returns(response);
clientInterfaceMock.Setup(x => x.RequestAsync(It.IsAny<string>(), It.IsAny<string>(), confMock, It.IsAny<bool>(), It.IsAny<RequestOptions>())).Returns(Task.FromResult(response));
var clientMock = new Client(It.IsAny<Config>())
{
HttpClient = clientInterfaceMock.Object,
Config = confMock
};
return clientMock;
}
19
View Source File : AuthInterceptorTests.cs
License : MIT License
Project Creator : AElfProject
License : MIT License
Project Creator : AElfProject
[Theory]
[InlineData("Ping")]
[InlineData("DoHandshake")]
public async Task UnaryServerHandler_NoAuth_Test(string methodName)
{
var helper = new MockServiceBuilder();
var unaryHandler = new UnaryServerMethod<string, string>((request, context) => Task.FromResult("ok"));
var method = new Method<string, string>(
MethodType.Unary,
nameof(PeerService),
methodName,
Marshallers.StringMarshaller,
Marshallers.StringMarshaller);
var serverServiceDefinition = ServerServiceDefinition.CreateBuilder()
.AddMethod(method, (request, context) => unaryHandler(request, context)).Build()
.Intercept(_authInterceptor);
helper.ServiceDefinition = serverServiceDefinition;
_server = helper.GetServer();
_server.Start();
_channel = helper.GetChannel();
var result = await Calls.AsyncUnaryCall(new CallInvocationDetails<string, string>(_channel, method, default),
"");
result.ShouldBe("ok");
}
19
View Source File : AuthInterceptorTests.cs
License : MIT License
Project Creator : AElfProject
License : MIT License
Project Creator : AElfProject
[Fact]
public async Task UnaryServerHandler_Auth_Failed()
{
var helper = new MockServiceBuilder();
helper.UnaryHandler = new UnaryServerMethod<string, string>((request, context) => Task.FromResult("ok"));
helper.ServiceDefinition = helper.ServiceDefinition.Intercept(_authInterceptor);
_server = helper.GetServer();
_server.Start();
_channel = helper.GetChannel();
await ShouldBeCancelRpcExceptionAsync(async () =>
await Calls.AsyncUnaryCall(helper.CreateUnaryCall(), ""));
var method = new Method<string, string>(MethodType.Unary, MockServiceBuilder.ServiceName, "Unary",
Marshallers.StringMarshaller, Marshallers.StringMarshaller);
var peer = _peerPool.GetPeersByHost("127.0.0.1").First();
((GrpcPeer) peer).InboundSessionId = new byte[] {1, 2, 3};
var callInvoker = helper.GetChannel().Intercept(metadata =>
{
metadata = new Metadata
{
{ GrpcConstants.PubkeyMetadataKey, peer.Info.Pubkey}
};
return metadata;
});
await ShouldBeCancelRpcExceptionAsync(async () =>
await callInvoker.AsyncUnaryCall(method, "localhost", new CallOptions(), ""));
callInvoker = helper.GetChannel().Intercept(metadata =>
{
metadata = new Metadata
{
{ GrpcConstants.PubkeyMetadataKey, peer.Info.Pubkey},
{ GrpcConstants.SessionIdMetadataKey, new byte[] {4, 5, 6 }}
};
return metadata;
});
await ShouldBeCancelRpcExceptionAsync(async () =>
await callInvoker.AsyncUnaryCall(method, "localhost", new CallOptions(), ""));
((GrpcPeer) peer).InboundSessionId = null;
await ShouldBeCancelRpcExceptionAsync(async () =>
await callInvoker.AsyncUnaryCall(method, "localhost", new CallOptions(), ""));
}
19
View Source File : AuthInterceptorTests.cs
License : MIT License
Project Creator : AElfProject
License : MIT License
Project Creator : AElfProject
[Fact]
public async Task UnaryServerHandler_Auth_Success()
{
var peer = _peerPool.GetPeersByHost("127.0.0.1").First();
((GrpcPeer) peer).InboundSessionId = new byte[] {1, 2, 3};
var helper = new MockServiceBuilder();
helper.UnaryHandler = new UnaryServerMethod<string, string>((request, context) =>
{
context.GetPeerInfo().ShouldBe(peer.ToString());
return Task.FromResult("ok");
});
helper.ServiceDefinition = helper.ServiceDefinition.Intercept(_authInterceptor);
_server = helper.GetServer();
_server.Start();
_channel = helper.GetChannel();
var method = new Method<string, string>(MethodType.Unary, MockServiceBuilder.ServiceName, "Unary",
Marshallers.StringMarshaller, Marshallers.StringMarshaller);
var callInvoker = helper.GetChannel().Intercept(metadata =>
{
metadata = new Metadata
{
{ GrpcConstants.PubkeyMetadataKey, peer.Info.Pubkey},
{ GrpcConstants.SessionIdMetadataKey, new byte[] {1, 2, 3}}
};
return metadata;
});
var result = await callInvoker.AsyncUnaryCall(method, "localhost", new CallOptions(), "");
result.ShouldBe("ok");
}
19
View Source File : AuthInterceptorTests.cs
License : MIT License
Project Creator : AElfProject
License : MIT License
Project Creator : AElfProject
[Fact]
public async Task ClientStreamingServerHandler_Auth_Failed()
{
var helper = new MockServiceBuilder();
helper.ClientStreamingHandler = new ClientStreamingServerMethod<string, string>((request, context) => Task.FromResult("ok"));
helper.ServiceDefinition = helper.ServiceDefinition.Intercept(_authInterceptor);
_server = helper.GetServer();
_server.Start();
_channel = helper.GetChannel();
await ShouldBeCancelRpcExceptionAsync(async () =>
await Calls.AsyncClientStreamingCall(helper.CreateClientStreamingCall()).ResponseAsync);
var method = new Method<string, string>(MethodType.ClientStreaming, MockServiceBuilder.ServiceName, "ClientStreaming",
Marshallers.StringMarshaller, Marshallers.StringMarshaller);
var peer = _peerPool.GetPeersByHost("127.0.0.1").First();
((GrpcPeer) peer).InboundSessionId = new byte[] {1, 2, 3};
var callInvoker = helper.GetChannel().Intercept(metadata =>
{
metadata = new Metadata
{
{ GrpcConstants.PubkeyMetadataKey, peer.Info.Pubkey},
{ GrpcConstants.SessionIdMetadataKey, new byte[] {4, 5, 6}}
};
return metadata;
});
await ShouldBeCancelRpcExceptionAsync(async () =>
await callInvoker.AsyncClientStreamingCall(method, "localhost", new CallOptions()).ResponseAsync);
}
19
View Source File : AuthInterceptorTests.cs
License : MIT License
Project Creator : AElfProject
License : MIT License
Project Creator : AElfProject
[Fact]
public async Task ClientStreamingServerHandler_Auth_Success()
{
var peer = _peerPool.GetPeersByHost("127.0.0.1").First();
((GrpcPeer) peer).InboundSessionId = new byte[] {1, 2, 3};
var helper = new MockServiceBuilder();
helper.ClientStreamingHandler = new ClientStreamingServerMethod<string, string>((request, context) =>
{
context.GetPeerInfo().ShouldBe(peer.ToString());
return Task.FromResult("ok");
});
helper.ServiceDefinition = helper.ServiceDefinition.Intercept(_authInterceptor);
_server = helper.GetServer();
_server.Start();
_channel = helper.GetChannel();
var method = new Method<string, string>(MethodType.ClientStreaming, MockServiceBuilder.ServiceName,
"ClientStreaming",
Marshallers.StringMarshaller, Marshallers.StringMarshaller);
var callInvoker = helper.GetChannel().Intercept(metadata =>
{
metadata = new Metadata
{
{GrpcConstants.PubkeyMetadataKey, peer.Info.Pubkey},
{GrpcConstants.SessionIdMetadataKey, new byte[] {1, 2, 3}}
};
return metadata;
});
var result = await callInvoker.AsyncClientStreamingCall(method, "localhost", new CallOptions()).ResponseAsync;
result.ShouldBe("ok");
}
19
View Source File : RetryInterceptorTest.cs
License : MIT License
Project Creator : AElfProject
License : MIT License
Project Creator : AElfProject
[Fact]
public async Task RetryDoesNotExceedSuccess()
{
var helper = new MockServiceBuilder("localhost");
int callCount = 0;
helper.UnaryHandler = new UnaryServerMethod<string, string>((request, context) =>
{
callCount++;
if (callCount == 1)
context.Status = new Status(StatusCode.Cancelled, "");
return Task.FromResult("ok");
});
_server = helper.GetServer();
_server.Start();
_channel = helper.GetChannel();
var callInvoker = helper.GetChannel().Intercept(new RetryInterceptor());
var metadata = new Metadata {{ GrpcConstants.RetryCountMetadataKey, "5"}};
await callInvoker.AsyncUnaryCall(new Method<string, string>(MethodType.Unary,
MockServiceBuilder.ServiceName, "Unary", Marshallers.StringMarshaller, Marshallers.StringMarshaller),
"localhost", new CallOptions().WithHeaders(metadata), "");
replacedert.Equal(2, callCount);
}
19
View Source File : RetryInterceptorTest.cs
License : MIT License
Project Creator : AElfProject
License : MIT License
Project Creator : AElfProject
[Fact]
public async Task RetryHeaderDecidesRetryCount()
{
var helper = new MockServiceBuilder("localhost");
int callCount = 0;
helper.UnaryHandler = new UnaryServerMethod<string, string>((request, context) =>
{
callCount++;
context.Status = new Status(StatusCode.Cancelled, "");
return Task.FromResult("ok");
});
_server = helper.GetServer();
_server.Start();
_channel = helper.GetChannel();
var callInvoker = helper.GetChannel().Intercept(new RetryInterceptor());
var metadata = new Metadata {{ GrpcConstants.RetryCountMetadataKey, "0"}};
await replacedert.ThrowsAsync<AggregateException>(async () => await callInvoker.AsyncUnaryCall(new Method<string, string>(MethodType.Unary,
MockServiceBuilder.ServiceName, "Unary", Marshallers.StringMarshaller, Marshallers.StringMarshaller),
"localhost", new CallOptions().WithHeaders(metadata), ""));
replacedert.Equal(1, callCount);
callCount = 0;
var oneRetryMetadata = new Metadata {{ GrpcConstants.RetryCountMetadataKey, "1"}};
await replacedert.ThrowsAsync<AggregateException>(async () => await callInvoker.AsyncUnaryCall(new Method<string, string>(MethodType.Unary,
MockServiceBuilder.ServiceName, "Unary", Marshallers.StringMarshaller, Marshallers.StringMarshaller),
"localhost", new CallOptions().WithHeaders(oneRetryMetadata), ""));
replacedert.Equal(2, callCount);
callCount = 0;
await replacedert.ThrowsAsync<AggregateException>(async () => await callInvoker.AsyncUnaryCall(new Method<string, string>(MethodType.Unary,
MockServiceBuilder.ServiceName, "Unary", Marshallers.StringMarshaller, Marshallers.StringMarshaller),
"localhost", new CallOptions(), ""));
replacedert.Equal(2, callCount);
}
19
View Source File : RetryInterceptorTest.cs
License : MIT License
Project Creator : AElfProject
License : MIT License
Project Creator : AElfProject
[Fact]
public async Task Retry_Timeout_Test()
{
var helper = new MockServiceBuilder("localhost");
int callCount = 0;
helper.UnaryHandler = new UnaryServerMethod<string, string>((request, context) =>
{
callCount++;
Task.Delay(1000).Wait();
return Task.FromResult("ok");
});
_server = helper.GetServer();
_server.Start();
_channel = helper.GetChannel();
var callInvoker = helper.GetChannel().Intercept(new RetryInterceptor());
var metadata = new Metadata {{ GrpcConstants.RetryCountMetadataKey, "1"}};
var exception = await replacedert.ThrowsAsync<AggregateException>(async () => await callInvoker.AsyncUnaryCall(
new Method<string, string>(MethodType.Unary,
MockServiceBuilder.ServiceName, "Unary", Marshallers.StringMarshaller,
Marshallers.StringMarshaller),
"localhost", new CallOptions().WithHeaders(metadata), ""));
var rpcException = exception.InnerExceptions[0] as RpcException;
rpcException.ShouldNotBeNull();
rpcException.StatusCode.ShouldBe(StatusCode.DeadlineExceeded);
replacedert.Equal(2, callCount);
}
19
View Source File : DbRepositorySimplifiedTest.cs
License : Apache License 2.0
Project Creator : agoda-com
License : Apache License 2.0
Project Creator : agoda-com
[Test]
public async Task ExecuteReaderAsync_Hit_Cache_Success()
{
SetupAsync();
object cachedValue = "cachedValue";
_cache.Setup(x => x.TryGetValue(It.IsAny<string>(), out cachedValue))
.Returns(true);
var result = await _db.ExecuteReaderAsync<string>("mobile_ro", "db.v1.sp_foo", 1,
2,new IDbDataParameter[]
{
new SqlParameter("@param1", "value1"),
new SqlParameter("@param2", "value2")
}, reader => Task.FromResult(cachedValue.ToString()), TimeSpan.MaxValue);
replacedert.AreEqual(cachedValue, result);
_cache.Verify(
x => x.TryGetValue(_expectedCacheKey, out cachedValue),
Times.Once);
_dbResources.Verify(x => x.ChooseDb("mobile_ro").SelectRandomly(), Times.Never);
replacedert.AreEqual(0, _onQueryCompleteEvents.Count);
}
19
View Source File : DbRepositoryTest.cs
License : Apache License 2.0
Project Creator : agoda-com
License : Apache License 2.0
Project Creator : agoda-com
public Task<string> ReadAsync(SqlMapper.GridReader reader)
=> Task.FromResult("multiple_result");
19
View Source File : RetryActionTest.cs
License : Apache License 2.0
Project Creator : agoda-com
License : Apache License 2.0
Project Creator : agoda-com
[Test]
public void ExecuteAction_Deny_Async_Result()
{
var errMsg = "Async action should be executed with ExecuteAsync.";
var mgr = new RetryAction<string>(() => "foo", UpdateWeight);
replacedert.Throws<ArgumentException>(
() => mgr.ExecuteAction<Task>((_1, _2) => Task.FromResult("Task"), (_1, _2) => true),
errMsg);
replacedert.Throws<ArgumentException>(
() => mgr.ExecuteAction<Task<string>>((_1, _2) => Task.FromResult("Task<T>"), (_1, _2) => true),
errMsg);
}
19
View Source File : RoleStore.cs
License : Apache License 2.0
Project Creator : Aguafrommars
License : Apache License 2.0
Project Creator : Aguafrommars
public virtual Task<string> GetRoleIdAsync(TRole role, CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
replacedertNotNull(role, nameof(role));
return Task.FromResult(ConvertIdToString(role.Id));
}
19
View Source File : EmptyDeviceAccessor.cs
License : MIT License
Project Creator : aguang-xyz
License : MIT License
Project Creator : aguang-xyz
public Task<string> GetSrcAsync()
{
return Task.FromResult(string.Empty);
}
19
View Source File : KeyRotationBuilderExtensionsTest.cs
License : Apache License 2.0
Project Creator : Aguafrommars
License : Apache License 2.0
Project Creator : Aguafrommars
[Fact]
public void ProtectKeysWithAzureKeyVault_should_throw_ArgumentNulException_on_builder_null()
{
replacedert.Throws<ArgumentNullException>(() => KeyRotationBuilderExtensions.ProtectKeysWithAzureKeyVault(null, null, null));
replacedert.Throws<ArgumentNullException>(() => KeyRotationBuilderExtensions.ProtectKeysWithAzureKeyVault(new KeyRotationBuilder(), null, null));
replacedert.Throws<ArgumentNullException>(() => KeyRotationBuilderExtensions.ProtectKeysWithAzureKeyVault(new KeyRotationBuilder(), new KeyVaultClient((a, r, s) => Task.FromResult("test")), null));
replacedert.Throws<ArgumentNullException>(() => KeyRotationBuilderExtensions.ProtectKeysWithAzureKeyVault(null, null, null, certificate: null));
replacedert.Throws<ArgumentNullException>(() => KeyRotationBuilderExtensions.ProtectKeysWithAzureKeyVault(null, null, "test", certificate: null));
replacedert.Throws<ArgumentNullException>(() => KeyRotationBuilderExtensions.ProtectKeysWithAzureKeyVault(null, null, null, clientSecret: null));
replacedert.Throws<ArgumentNullException>(() => KeyRotationBuilderExtensions.ProtectKeysWithAzureKeyVault(null, null, "test", clientSecret: null));
}
19
View Source File : TestSuite.cs
License : MIT License
Project Creator : ahydrax
License : MIT License
Project Creator : ahydrax
public Task<string> Done() => Task.FromResult("ALL DONE");
19
View Source File : TokenService.cs
License : MIT License
Project Creator : albyho
License : MIT License
Project Creator : albyho
public Task<string> GenerateRefreshTokenAsync(int userId)
{
var randomNumber = new byte[32];
using (var rng = RandomNumberGenerator.Create())
{
rng.GetBytes(randomNumber);
var refreshToken = Convert.ToBase64String(randomNumber);
var cacheKey = CacheKeyFormat.FormatWith(userId);
_cache.SetStringAsync(cacheKey, refreshToken, new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(_tokenValidationSettings.ExpiresSeconds + _tokenValidationSettings.ClockSkewSeconds + _tokenValidationSettings.RefreshTokenExpiresSeconds)
}).ContinueWithOnFaultedHandleLog(_logger);
return Task.FromResult(refreshToken);
}
}
19
View Source File : SqlQueryable.cs
License : MIT License
Project Creator : AlenToma
License : MIT License
Project Creator : AlenToma
public async Task<string> JsonAsync(JSONParameters param = null)
{
return await Task.FromResult<string>(Execute().ToJson(param));
}
19
View Source File : SqlQueryable.cs
License : MIT License
Project Creator : AlenToma
License : MIT License
Project Creator : AlenToma
public async Task<string> XmlAsync()
{
return await Task.FromResult<string>(Execute().ToXml());
}
19
View Source File : NoopRoleStore.cs
License : MIT License
Project Creator : alexandre-spieser
License : MIT License
Project Creator : alexandre-spieser
public Task<string> GetRoleNameAsync(TestRole role, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult<string>(null);
}
19
View Source File : NoopRoleStore.cs
License : MIT License
Project Creator : alexandre-spieser
License : MIT License
Project Creator : alexandre-spieser
public Task<string> GetRoleIdAsync(TestRole role, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult<string>(null);
}
19
View Source File : NoopRoleStore.cs
License : MIT License
Project Creator : alexandre-spieser
License : MIT License
Project Creator : alexandre-spieser
public Task<string> GetNormalizedRoleNameAsync(TestRole role, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult<string>(null);
}
19
View Source File : NoopUserStore.cs
License : MIT License
Project Creator : alexandre-spieser
License : MIT License
Project Creator : alexandre-spieser
public Task<string> GetNormalizedUserNameAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult<string>(null);
}
19
View Source File : MongoRoleStore.cs
License : MIT License
Project Creator : alexandre-spieser
License : MIT License
Project Creator : alexandre-spieser
public virtual Task<string> GetRoleIdAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
if (role == null)
{
throw new ArgumentNullException(nameof(role));
}
return Task.FromResult(ConvertIdToString(role.Id));
}
19
View Source File : HostInfoController.cs
License : MIT License
Project Creator : alexyakunin
License : MIT License
Project Creator : alexyakunin
[HttpGet]
public Task<string> GetHostName(CancellationToken cancellationToken = default)
=> Task.FromResult(Environment.MachineName);
19
View Source File : ManageControllerTests.cs
License : MIT License
Project Creator : alimon808
License : MIT License
Project Creator : alimon808
public override Task<string> GenerateChangePhoneNumberTokenAsync(ApplicationUser user, string phoneNumber)
{
return Task.FromResult("change-phone-number-token");
}
19
View Source File : TokenControllerTests.cs
License : MIT License
Project Creator : alimon808
License : MIT License
Project Creator : alimon808
public override Task<string> GeneratePreplacedwordResetTokenAsync(ApplicationUser user)
{
return Task.FromResult("reset-preplacedword-token");
}
19
View Source File : TokenControllerTests.cs
License : MIT License
Project Creator : alimon808
License : MIT License
Project Creator : alimon808
public override Task<string> GenerateTwoFactorTokenAsync(ApplicationUser user, string tokenProvider)
{
return Task.FromResult("two-factor-token");
}
19
View Source File : TokenControllerTests.cs
License : MIT License
Project Creator : alimon808
License : MIT License
Project Creator : alimon808
public override Task<string> GetEmailAsync(ApplicationUser user)
{
return Task.FromResult("[email protected]");
}
19
View Source File : TokenControllerTests.cs
License : MIT License
Project Creator : alimon808
License : MIT License
Project Creator : alimon808
public override Task<string> GetPhoneNumberAsync(ApplicationUser user)
{
return Task.FromResult("224-555-0123");
}
19
View Source File : AccountControllerTests.cs
License : MIT License
Project Creator : alimon808
License : MIT License
Project Creator : alimon808
public override Task<string> GenerateEmailConfirmationTokenAsync(ApplicationUser user)
{
return Task.FromResult("token string");
}
19
View Source File : MemoryCache.cs
License : MIT License
Project Creator : alonsoalon
License : MIT License
Project Creator : alonsoalon
public Task<string> GetAsync(string key)
{
return Task.FromResult(Get(key));
}
19
View Source File : BasePathStrategy.cs
License : MIT License
Project Creator : alonsoalon
License : MIT License
Project Creator : alonsoalon
public async Task<string> GetIdentifierAsync(object context)
{
if (!(context is HttpContext))
throw new MulreplacedenantException(null,
new ArgumentException($"\"{nameof(context)}\" 必须是HttpContext类型 ", nameof(context)));
var path = (context as HttpContext).Request.Path;
var pathSegments =
path.Value.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
if (pathSegments.Length == 0)
return null;
string identifier = pathSegments[0];
return await Task.FromResult(identifier);
}
19
View Source File : DelegateStrategy.cs
License : MIT License
Project Creator : alonsoalon
License : MIT License
Project Creator : alonsoalon
public async Task<string> GetIdentifierAsync(object context)
{
var identifier = await doStrategy(context);
return await Task.FromResult(identifier);
}
19
View Source File : HostStrategy.cs
License : MIT License
Project Creator : alonsoalon
License : MIT License
Project Creator : alonsoalon
public async Task<string> GetIdentifierAsync(object context)
{
if (!(context is HttpContext))
throw new MulreplacedenantException(null,
new ArgumentException($"\"{nameof(context)}\" type must be of type HttpContext", nameof(context)));
var host = (context as HttpContext).Request.Host;
if (host.HasValue == false)
return null;
string identifier = null;
var match = Regex.Match(host.Host, regex,
RegexOptions.ExplicitCapture,
TimeSpan.FromMilliseconds(100));
if (match.Success)
{
identifier = match.Groups["identifier"].Value;
}
return await Task.FromResult(identifier);
}
19
View Source File : RouteStrategy.cs
License : MIT License
Project Creator : alonsoalon
License : MIT License
Project Creator : alonsoalon
public async Task<string> GetIdentifierAsync(object context)
{
if (!(context is HttpContext))
throw new MulreplacedenantException(null,
new ArgumentException($"\"{nameof(context)}\" 必须是HttpContext类型 ", nameof(context)));
var httpContext = context as HttpContext;
object identifier = null;
httpContext.Request.RouteValues.TryGetValue(tenantParam, out identifier);
return await Task.FromResult(identifier as string);
}
See More Examples