public async Task ChangeBlockingAsync_ReturnNotFound_And_DoNotChangeClientsInDb_When_PassingNotExistingClientId() { Guid[] ids = new Guid[3]; ids[0] = await this.InsertDefaultClient(1); ids[1] = await this.InsertDefaultClient(2); ids[2] = await this.InsertDefaultClient(3); var repository = new SqlCeClientRepository(this.ConnectionFactory); var notExisintGuid = Guid.NewGuid(); while (ids.Contains(notExisintGuid)) { notExisintGuid = Guid.NewGuid(); } RepositoryResponse response = await repository.ChangeBlockingAsync(new IdSrvClientBlockDto { Id = notExisintGuid, IsBlocked = true }); Assert.AreEqual(RepositoryResponse.NotFound, response); using (IDbConnection connection = await this.ConnectionFactory.GetConnectionAsync()) { var compiler = new SqlServerCompiler(); var db = new QueryFactory(connection, compiler); this.ConnectionFactory = new SqlCeConnectionFactory(this.TestConnectionString); IEnumerable <IdSrvClientDto> clients = await db.Query("Clients").GetAsync <IdSrvClientDto>(); Assert.AreEqual(3, clients.Count()); for (int i = 1; i <= 3; ++i) { Assert.AreEqual(ids[i - 1], clients.ElementAt(i - 1).Id); Assert.AreEqual($"n{i}", clients.ElementAt(i - 1).Name); Assert.AreEqual($"u{i}", clients.ElementAt(i - 1).Uri); Assert.AreEqual($"p{i}", clients.ElementAt(i - 1).Secret); Assert.AreEqual(false, clients.ElementAt(i - 1).IsBlocked); } } }
public async Task ChangeBlockingAsync_ReturnNotFound_And_DoNotChangeClientsInDb_When_ClientDbIsEmpty() { var repository = new SqlCeClientRepository(this.ConnectionFactory); RepositoryResponse response = await repository.ChangeBlockingAsync(new IdSrvClientBlockDto { Id = Guid.NewGuid(), IsBlocked = true }); Assert.AreEqual(RepositoryResponse.NotFound, response); using (IDbConnection connection = await this.ConnectionFactory.GetConnectionAsync()) { var compiler = new SqlServerCompiler(); var db = new QueryFactory(connection, compiler); this.ConnectionFactory = new SqlCeConnectionFactory(this.TestConnectionString); IEnumerable <IdSrvClientDto> clients = await db.Query("Clients").GetAsync <IdSrvClientDto>(); Assert.AreEqual(0, clients.Count()); } }
public async Task UpdateAsync_ReturnNotFound_When_PassingNotExisintClientId_And_DbNotContainsAnyClient() { var repository = new SqlCeClientRepository(this.ConnectionFactory); RepositoryResponse response = await repository.UpdateAsync(new UpdateIdSrvClientDto { Id = Guid.NewGuid(), Name = "n", Secret = "s" }); Assert.AreEqual(RepositoryResponse.NotFound, response); using (IDbConnection connection = await this.ConnectionFactory.GetConnectionAsync()) { var compiler = new SqlServerCompiler(); var db = new QueryFactory(connection, compiler); this.ConnectionFactory = new SqlCeConnectionFactory(this.TestConnectionString); IEnumerable <IdSrvClientDto> clients = await db.Query("Clients").GetAsync <IdSrvClientDto>(); Assert.AreEqual(0, clients.Count()); } }
public async Task CreateAsync_ReturnSuccess_And_CreateNotBlockedUserInDb_When_PassingClientWithUri_And_DbNotContainsAnyClient() { var repository = new SqlCeClientRepository(this.ConnectionFactory); RepositoryResponse response = await repository.CreateAsync(new NewIdSrvClientDto { Name = "n", Secret = "s", Uri = "u" }); Assert.AreEqual(RepositoryResponse.Success, response); using (IDbConnection connection = await this.ConnectionFactory.GetConnectionAsync()) { var compiler = new SqlServerCompiler(); var db = new QueryFactory(connection, compiler); this.ConnectionFactory = new SqlCeConnectionFactory(this.TestConnectionString); IEnumerable <IdSrvClientDto> clients = await db.Query("Clients").GetAsync <IdSrvClientDto>(); Assert.AreEqual(1, clients.Count()); IdSrvClientDto createdClient = clients.ElementAt(0); Assert.AreEqual("n", createdClient.Name); Assert.AreEqual("s", createdClient.Secret); Assert.AreEqual("u", createdClient.Uri); Assert.IsFalse(createdClient.IsBlocked); } }
public async Task DeleteAsync_ReturnNotFound_When_PassingIdForNotExisingClient() { Guid[] ids = new Guid[3]; ids[0] = await this.InsertDefaultClient(1); ids[1] = await this.InsertDefaultClient(2, false); ids[2] = await this.InsertDefaultClient(3, isBlocked : true); var notExistingId = Guid.NewGuid(); while (ids.Contains(notExistingId)) { notExistingId = Guid.NewGuid(); } var repository = new SqlCeClientRepository(this.ConnectionFactory); RepositoryResponse response = await repository.DeleteAsync(notExistingId); Assert.AreEqual(RepositoryResponse.NotFound, response); }
public async Task GetByIdAsync_ReturnNull_When_PassingIdForNotExisingClient() { Guid[] ids = new Guid[3]; ids[0] = await this.InsertDefaultClient(1); ids[1] = await this.InsertDefaultClient(2, false); ids[2] = await this.InsertDefaultClient(3, isBlocked : true); var notExistingId = Guid.NewGuid(); while (ids.Contains(notExistingId)) { notExistingId = Guid.NewGuid(); } var repository = new SqlCeClientRepository(this.ConnectionFactory); IdSrvClientDto client = await repository.GetByIdAsync(notExistingId); Assert.IsNull(client); }
public async Task GetAllAsync_ReturnAllClients_When_Invoked() { Guid[] ids = new Guid[3]; ids[0] = await this.InsertDefaultClient(1); ids[1] = await this.InsertDefaultClient(2, false); ids[2] = await this.InsertDefaultClient(3, isBlocked : true); var repository = new SqlCeClientRepository(this.ConnectionFactory); IEnumerable <IdSrvClientDto> clients = await repository.GetAllAsync(); Assert.IsNotNull(clients); Assert.AreEqual(3, clients.Count()); for (int i = 1; i <= 3; ++i) { Assert.AreEqual(ids[i - 1], clients.ElementAt(i - 1).Id); Assert.AreEqual($"n{i}", clients.ElementAt(i - 1).Name); Assert.AreEqual(i == 2 ? null : $"u{i}", clients.ElementAt(i - 1).Uri); Assert.AreEqual($"p{i}", clients.ElementAt(i - 1).Secret); Assert.AreEqual(i == 3, clients.ElementAt(i - 1).IsBlocked); } }
public async Task UpdateAsync_ReturnConflict_And_DoNotChangeClientsInDb_When_PassingAlreadyExistingName() { Guid[] ids = new Guid[3]; ids[0] = await this.InsertDefaultClient(1); ids[1] = await this.InsertDefaultClient(2); ids[2] = await this.InsertDefaultClient(3); var repository = new SqlCeClientRepository(this.ConnectionFactory); RepositoryResponse response = await repository.UpdateAsync(new UpdateIdSrvClientDto { Id = ids[1], Name = "n3", Secret = "p", Uri = "u" }); Assert.AreEqual(RepositoryResponse.Conflict, response); using (IDbConnection connection = await this.ConnectionFactory.GetConnectionAsync()) { var compiler = new SqlServerCompiler(); var db = new QueryFactory(connection, compiler); this.ConnectionFactory = new SqlCeConnectionFactory(this.TestConnectionString); IEnumerable <IdSrvClientDto> clients = await db.Query("Clients").GetAsync <IdSrvClientDto>(); Assert.AreEqual(3, clients.Count()); for (int i = 1; i <= 3; ++i) { Assert.AreEqual(ids[i - 1], clients.ElementAt(i - 1).Id); Assert.AreEqual($"n{i}", clients.ElementAt(i - 1).Name); Assert.AreEqual($"u{i}", clients.ElementAt(i - 1).Uri); Assert.AreEqual($"p{i}", clients.ElementAt(i - 1).Secret); Assert.AreEqual(false, clients.ElementAt(i - 1).IsBlocked); } } }
public void ChangeBlockingAsync_ThrowsArgumentNullException_When_PassingNullAsDto() { var repository = new SqlCeClientRepository(this.ConnectionFactory); Assert.ThrowsAsync <ArgumentNullException>(() => repository.ChangeBlockingAsync(null)); }
public void GetByNameAsync_ThrowsArgumentNullException_When_PassingNullName() { var repository = new SqlCeClientRepository(this.ConnectionFactory); Assert.ThrowsAsync <ArgumentNullException>(() => repository.GetByNameAsync(null)); }