public void GetTipoPersona_ParamatersMatchExpectedValues() { // Arrange var dbOptions = new DbContextOptionsBuilder <VisitPopDbContext>() .UseInMemoryDatabase(databaseName: $"VisitPopDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeTipoPersona = new FakeTipoPersona { }.Generate(); // Act using (var context = new VisitPopDbContext(dbOptions)) { context.PersonTypes.AddRange(fakeTipoPersona); context.SaveChanges(); var service = new PersonTypeRepository(context, new SieveProcessor(sieveOptions)); // Assert var tipoPersonaById = service.GetPersonType(fakeTipoPersona.Id); tipoPersonaById.Id.Should().Be(fakeTipoPersona.Id); tipoPersonaById.Name.Should().Be(fakeTipoPersona.Name); } }
public async void GetTipoPersonaAsync_ReturnExpectedPageSize() { // Arrange var dbOptions = new DbContextOptionsBuilder <VisitPopDbContext>() .UseInMemoryDatabase(databaseName: $"TipoPersonaDb{Guid.NewGuid()}") .Options; var sieveOptios = Options.Create(new SieveOptions()); var fakeTipoPeronaOne = new FakeTipoPersona { }.Ignore(t => t.Id).Generate(); fakeTipoPeronaOne.Id = 1; var fakeTipoPeronaTwo = new FakeTipoPersona { }.Ignore(t => t.Id).Generate(); fakeTipoPeronaTwo.Id = 2; var fakeTipoPeronaThree = new FakeTipoPersona { }.Ignore(t => t.Id).Generate(); fakeTipoPeronaThree.Id = 3; // Act using (var context = new VisitPopDbContext(dbOptions)) { context.PersonTypes.AddRange(fakeTipoPeronaOne, fakeTipoPeronaTwo, fakeTipoPeronaThree); context.SaveChanges(); var service = new PersonTypeRepository(context, new SieveProcessor(sieveOptios)); var tipoPersonaRepo = await service.GetTipoPersonas(new PersonTypeParametersDto { PageSize = 2 }); // Assert tipoPersonaRepo.Should() .NotBeEmpty() .And.HaveCount(2); tipoPersonaRepo.Should().ContainEquivalentOf(fakeTipoPeronaOne); tipoPersonaRepo.Should().ContainEquivalentOf(fakeTipoPeronaTwo); context.Database.EnsureDeleted(); } }
public async Task GetTipoPersonas_ReturnsSuccessCodeAndResourceWithAccurateFields() { var fakeTipoPersonaOne = new FakeTipoPersona { }.Ignore(t => t.Id).Generate(); var fakeTipoPersonaTwo = new FakeTipoPersona { }.Ignore(t => t.Id).Generate(); var appFactory = _factory; using (var scope = appFactory.Services.CreateScope()) { var context = scope.ServiceProvider.GetRequiredService <VisitPopDbContext>(); context.Database.EnsureCreated(); //context.TipoPersonas.RemoveRange(context.TipoPersonas); context.PersonTypes.AddRange(fakeTipoPersonaOne, fakeTipoPersonaTwo); context.SaveChanges(); } var client = appFactory.CreateClient(new WebApplicationFactoryClientOptions { AllowAutoRedirect = false }); var result = await client.GetAsync("api/TipoPersonas") .ConfigureAwait(false); var responseContent = await result.Content.ReadAsStringAsync() .ConfigureAwait(false); var response = JsonConvert.DeserializeObject <PageListTipoPersona>(responseContent).TipoPersonas; // Assert result.StatusCode.Should().Be(200); response.Should().ContainEquivalentOf(fakeTipoPersonaOne, options => options.ExcludingMissingMembers()); response.Should().ContainEquivalentOf(fakeTipoPersonaTwo, options => options.ExcludingMissingMembers()); }
public async void GetTipoPersonasAsync_FilterNombreListWithExact() { // Arrange var dbOptions = new DbContextOptionsBuilder <VisitPopDbContext>() .UseInMemoryDatabase(databaseName: $"TipoPersonaDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeTipoPersonaOne = new FakeTipoPersona { }.Generate(); fakeTipoPersonaOne.Name = "alpha"; var fakeTipoPersonaTwo = new FakeTipoPersona { }.Generate(); fakeTipoPersonaTwo.Name = "bravo"; var fakeTipoPersonaThree = new FakeTipoPersona { }.Generate(); fakeTipoPersonaThree.Name = "charlie"; // Act using (var context = new VisitPopDbContext(dbOptions)) { context.PersonTypes.AddRange(fakeTipoPersonaOne, fakeTipoPersonaTwo, fakeTipoPersonaThree); context.SaveChanges(); var service = new PersonTypeRepository(context, new SieveProcessor(sieveOptions)); var tipoPersonaRepo = await service.GetTipoPersonas(new PersonTypeParametersDto { Filters = $"Nombre == {fakeTipoPersonaTwo.Name}" }); // Assert tipoPersonaRepo.Should() .HaveCount(1); context.Database.EnsureDeleted(); } }
public async void GetTipoPersonasAsync_ListTipoPersonaIdSortedInDescOrder() { // Arrange var dbOptions = new DbContextOptionsBuilder <VisitPopDbContext>() .UseInMemoryDatabase(databaseName: $"TipoPersonaDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeTipoPersonaOne = new FakeTipoPersona { }.Generate(); fakeTipoPersonaOne.Id = 2; var fakeTipoPersonaTwo = new FakeTipoPersona { }.Generate(); fakeTipoPersonaTwo.Id = 1; var fakeTipoPersonaThree = new FakeTipoPersona { }.Generate(); fakeTipoPersonaThree.Id = 3; // Act using (var context = new VisitPopDbContext(dbOptions)) { context.PersonTypes.AddRange(fakeTipoPersonaOne, fakeTipoPersonaTwo, fakeTipoPersonaThree); context.SaveChanges(); var service = new PersonTypeRepository(context, new SieveProcessor(sieveOptions)); var tipoPersonaRepo = await service.GetTipoPersonas(new PersonTypeParametersDto { SortOrder = "-Id" }); // Assert tipoPersonaRepo.Should() .ContainInOrder(fakeTipoPersonaThree, fakeTipoPersonaOne, fakeTipoPersonaTwo); context.Database.EnsureDeleted(); } }
public void DeleteTipoPersona_ReturnsProperCount() { //Arrange var dbOptions = new DbContextOptionsBuilder <VisitPopDbContext>() .UseInMemoryDatabase(databaseName: $"TipoPersonaDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeTipoPersonaOne = new FakeTipoPersona { }.Generate(); var fakeTipoPersonaTwo = new FakeTipoPersona { }.Generate(); var fakeTipoPersonaThree = new FakeTipoPersona { }.Generate(); //Act using (var context = new VisitPopDbContext(dbOptions)) { context.PersonTypes.AddRange(fakeTipoPersonaOne, fakeTipoPersonaTwo, fakeTipoPersonaThree); var service = new PersonTypeRepository(context, new SieveProcessor(sieveOptions)); service.DeletePersonType(fakeTipoPersonaTwo); context.SaveChanges(); //Assert var TipoPersonList = context.PersonTypes.ToList(); TipoPersonList.Should() .NotBeEmpty() .And.HaveCount(2); TipoPersonList.Should().ContainEquivalentOf(fakeTipoPersonaOne); TipoPersonList.Should().ContainEquivalentOf(fakeTipoPersonaThree); Assert.DoesNotContain(TipoPersonList, a => a == fakeTipoPersonaTwo); context.Database.EnsureDeleted(); } }
public async Task PutTipoPersonaReturnsBodyAndFieldsWereSuccessfullyUpdated() { //Arrange var mapper = new MapperConfiguration(cfg => { cfg.AddProfile <PersonTypeProfile>(); }).CreateMapper(); var fakeTipoPersonaOne = new FakeTipoPersona { }.Ignore(t => t.Id).Generate(); var expectedFinalObject = mapper.Map <PersonTypeDto>(fakeTipoPersonaOne); expectedFinalObject.Name = "Easily Identified Value For Test"; var appFactory = _factory; using (var scope = appFactory.Services.CreateScope()) { var context = scope.ServiceProvider.GetRequiredService <VisitPopDbContext>(); context.Database.EnsureCreated(); //context.TipoPersonas.RemoveRange(context.TipoPersonas); context.PersonTypes.AddRange(fakeTipoPersonaOne); context.SaveChanges(); } var client = appFactory.CreateClient(new WebApplicationFactoryClientOptions { AllowAutoRedirect = false }); var serializedTipoPersonaToUpdate = JsonConvert.SerializeObject(expectedFinalObject); // Act // get the value i want to update. assumes I can use sieve for this field. if this is not an option, just use something else var getResult = await client.GetAsync($"api/TipoPersonas/?filters=Nombre=={fakeTipoPersonaOne.Name}") .ConfigureAwait(false); var getResponseContent = await getResult.Content.ReadAsStringAsync() .ConfigureAwait(false); //var getResponse = JsonConvert.DeserializeObject<IEnumerable<TipoPersonaDto>>(getResponseContent); var getResponse = JsonConvert.DeserializeObject <PageListTipoPersona>(getResponseContent).TipoPersonas; var id = getResponse.FirstOrDefault().Id; expectedFinalObject.Id = id; // put it var patchResult = await client.PutAsJsonAsync($"api/TipoPersonas/{id}", expectedFinalObject) .ConfigureAwait(false); // get it again to confirm updates var checkResult = await client.GetAsync($"api/TipoPersonas/{id}") .ConfigureAwait(false); var checkResponseContent = await checkResult.Content.ReadAsStringAsync() .ConfigureAwait(false); //var checkResponse = JsonConvert.DeserializeObject<TipoPersonaDto>(checkResponseContent); var checkResponse = JsonConvert.DeserializeObject <TipoPersonaResponseDto>(checkResponseContent).TipoPersona; // Assert patchResult.StatusCode.Should().Be(204); checkResponse.Should().BeEquivalentTo(expectedFinalObject, options => options.ExcludingMissingMembers()); }