public static IKronosClient CreateClient(string configFilePath) { string configContent = File.ReadAllText(configFilePath); KronosConfig config = JsonConvert.DeserializeObject <KronosConfig>(configContent); return(new KronosClient(config)); }
public async Task Delete_CallsSendToServerAsync() { var connectionMock = Substitute.For <IConnection>(); connectionMock.SendAsync(Arg.Any <DeleteRequest>()) .Returns(SerializationUtils.Serialize(true)); KronosConfig config = LoadTestConfiguration(); IKronosClient client = new KronosClient(config, endpoint => connectionMock); await client.DeleteAsync("key"); await connectionMock.Received(1).SendAsync(Arg.Any <DeleteRequest>()); }
private static IKronosClient CreateInternal(string domain, string ip, int port) { var config = new KronosConfig { ClusterConfig = new ClusterConfig { Servers = new[] { new ServerConfig { Domain = domain, Ip = ip, Port = port } } } }; return(new KronosClient(config)); }
public async Task Get_DoestNotReturnObject() { byte[] serverResponse = SerializationUtils.Serialize(RequestStatusCode.NotFound); var connectionMock = Substitute.For <IConnection>(); connectionMock.SendAsync(Arg.Any <GetRequest>()) .Returns(SerializationUtils.Serialize(serverResponse)); KronosConfig config = LoadTestConfiguration(); IKronosClient client = new KronosClient(config, endpoint => connectionMock); byte[] response = await client.GetAsync("key"); Assert.Null(response); await connectionMock.Received(1).SendAsync(Arg.Any <GetRequest>()); }
public async Task Count_ReturnsNumberOfElementsInStorage() { int countPerServer = 5; var connectionMock = Substitute.For <IConnection>(); connectionMock.SendAsync(Arg.Any <CountRequest>()) .Returns(SerializationUtils.Serialize(countPerServer)); KronosConfig config = LoadTestConfiguration(); int serverCount = config.ClusterConfig.Servers.Length; IKronosClient client = new KronosClient(config, endpoint => connectionMock); int sum = await client.CountAsync(); Assert.Equal(sum, countPerServer * serverCount); await connectionMock.Received(serverCount).SendAsync(Arg.Any <CountRequest>()); }
public async Task Contains_ReturnsTrueIfElementExistsInStorage() { bool expected = true; string key = "lorem ipsum"; var connectionMock = Substitute.For <IConnection>(); connectionMock.SendAsync(Arg.Any <ContainsRequest>()) .Returns(SerializationUtils.Serialize(expected)); KronosConfig config = LoadTestConfiguration(); IKronosClient client = new KronosClient(config, endpoint => connectionMock); bool exists = await client.ContainsAsync(key); Assert.Equal(expected, exists); await connectionMock.Received(1).SendAsync(Arg.Any <ContainsRequest>()); }
public async Task Insert_InsertsObjectToStorage() { string key = "key"; byte[] package = Encoding.UTF8.GetBytes("package"); DateTime expiryDate = DateTime.Today.AddDays(1); var connectionMock = Substitute.For <IConnection>(); connectionMock.SendAsync(Arg.Any <IRequest>()) .Returns(SerializationUtils.Serialize(true)); KronosConfig config = LoadTestConfiguration(); IKronosClient client = new KronosClient(config, endpoint => connectionMock); await client.InsertAsync(key, package, expiryDate); await connectionMock.Received(1).SendAsync(Arg.Any <InsertRequest>()); }
public async Task Get_ReturnsObject() { const string word = "lorem ipsum"; byte[] package = SerializationUtils.Serialize(word); var connectionMock = Substitute.For <IConnection>(); connectionMock.SendAsync(Arg.Any <GetRequest>()) .Returns(SerializationUtils.Serialize(package)); KronosConfig config = LoadTestConfiguration(); IKronosClient client = new KronosClient(config, endpoint => connectionMock); byte[] response = await client.GetAsync("key"); string responseString = SerializationUtils.Deserialize <string>(response); Assert.Equal(responseString, word); await connectionMock.Received(1).SendAsync(Arg.Any <GetRequest>()); }
private static IKronosClient CreateInternal(string domain, string ip, int port, string login, string password) { var config = new KronosConfig { ClusterConfig = new ClusterConfig { Servers = new[] { new ServerConfig { Domain = domain, Ip = ip, Port = port, Credentials = new AuthConfig { Login = login, Password = password } } } } }; return(new KronosClient(config)); }
internal KronosClient(KronosConfig config, Func <IPEndPoint, IConnection> connectionResolver) { _serverProvider = new ServerProvider(config.ClusterConfig); _connectionResolver = connectionResolver; }
public KronosClient(KronosConfig config) : this(config, endpoint => new Connection(endpoint)) { }
public KronosClient(KronosConfig config) { _serverProvider = new ServerProvider(config.ClusterConfig); }