public async Task CreateAsync_ReturnConflict_And_DoNotChangeDb_When_PassingClientNameAlreadyExists() { 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.CreateAsync(new NewIdSrvClientDto { Name = "n1", Secret = "s", 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 async Task CreateAsync_ReturnSuccess_And_CreateNotBlockedUserInDb_When_PassingClientWithUri() { await this.InsertDefaultClient(1); await this.InsertDefaultClient(2); await this.InsertDefaultClient(3); 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(4, clients.Count()); IdSrvClientDto createdClient = clients.Where(c => c.Name == "n").FirstOrDefault(); Assert.IsNotNull(createdClient); Assert.AreEqual("n", createdClient.Name); Assert.AreEqual("s", createdClient.Secret); Assert.AreEqual("u", createdClient.Uri); Assert.IsFalse(createdClient.IsBlocked); } }
public void CreateAsync_ThrowsArgumentNullException_When_PassingNullSecret() { var repository = new SqlCeClientRepository(this.ConnectionFactory); Assert.ThrowsAsync <ArgumentNullException>(() => repository.CreateAsync(new NewIdSrvClientDto { Name = "n" })); }
public async Task CreateAsync_ReturnSuccess_And_CreateNotBlockedUserInDb_When_PassingClientWithoutUri_And_DbNotContainsAnyClient() { var repository = new SqlCeClientRepository(this.ConnectionFactory); RepositoryResponse response = await repository.CreateAsync(new NewIdSrvClientDto { Name = "n", Secret = "s" }); 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.IsNull(createdClient.Uri); Assert.IsFalse(createdClient.IsBlocked); } }
public void CreateAsync_ThrowsArgumentNullException_When_PassingNullAsDto() { var repository = new SqlCeClientRepository(this.ConnectionFactory); Assert.ThrowsAsync <ArgumentNullException>(() => repository.CreateAsync(null)); }