public void GetEmployee_ParametersMatchExpectedValues() { //Arrange var dbOptions = new DbContextOptionsBuilder <VisitPopDbContext>() .UseInMemoryDatabase(databaseName: $"EmployeeDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeEmployee = new FakeEmployee { }.Generate(); //Act using (var context = new VisitPopDbContext(dbOptions)) { context.Employees.AddRange(fakeEmployee); context.SaveChanges(); var service = new EmployeeRepository(context, new SieveProcessor(sieveOptions)); //Assert var empleadoById = service.GetEmployee(fakeEmployee.Id); empleadoById.Id.Should().Be(fakeEmployee.Id); empleadoById.FirstName.Should().Be(fakeEmployee.FirstName); empleadoById.LastName.Should().Be(fakeEmployee.LastName); empleadoById.DocId.Should().Be(fakeEmployee.DocId); empleadoById.PhoneNumber.Should().Be(fakeEmployee.PhoneNumber); empleadoById.EmployeeDepartmentId.Should().Be(fakeEmployee.EmployeeDepartmentId); empleadoById.EmailAddress.Should().Be(fakeEmployee.EmailAddress); empleadoById.EmployeeDepartments.Should().Be(fakeEmployee.EmployeeDepartments); } }
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 void GetEmployeeDepartment_ParametersMatchExpectedValues() { //Arrange var dbOptions = new DbContextOptionsBuilder <VisitPopDbContext>() .UseInMemoryDatabase(databaseName: $"EmployeeDepartmentDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeEmployeeDepartment = new FakeEmployeeDepartment { }.Generate(); //Act using (var context = new VisitPopDbContext(dbOptions)) { context.EmployeeDepartments.AddRange(fakeEmployeeDepartment); context.SaveChanges(); var service = new EmployeeDepartmentRepository(context, new SieveProcessor(sieveOptions)); //Assert var EmployeeDepartmentById = service.GetEmployeeDepartment(fakeEmployeeDepartment.Id); EmployeeDepartmentById.Id.Should().Be(fakeEmployeeDepartment.Id); EmployeeDepartmentById.Name.Should().Be(fakeEmployeeDepartment.Name); } }
public PersonRepository(VisitPopDbContext context, SieveProcessor sieve) { _context = context ?? throw new ArgumentNullException(nameof(context)); _sieve = sieve ?? throw new ArgumentNullException(nameof(sieve)); }
public EmployeeRepository(VisitPopDbContext context, SieveProcessor sieveProcessor) { _context = context ?? throw new ArgumentNullException(nameof(context)); _sieveProcessor = sieveProcessor ?? throw new ArgumentNullException(nameof(sieveProcessor)); }
public static void SeedVisitStateData(VisitPopDbContext context) { if (!context.VisitStates.Any()) { context.VisitStates.Add(new AutoFaker <VisitState>()); context.VisitStates.Add(new AutoFaker <VisitState>()); context.VisitStates.Add(new AutoFaker <VisitState>()); context.SaveChanges(); } }
public static void VehicleTypeSampleData(VisitPopDbContext context) { if (!context.VehicleTypes.Any()) { context.VehicleTypes.Add(new AutoFaker <VehicleType>()); context.VehicleTypes.Add(new AutoFaker <VehicleType>()); context.VehicleTypes.Add(new AutoFaker <VehicleType>()); context.SaveChanges(); } }
public static void SeedEmpresaData(VisitPopDbContext context) { if (!context.Companies.Any()) { context.Companies.Add(new AutoFaker <Company>()); context.Companies.Add(new AutoFaker <Company>()); context.Companies.Add(new AutoFaker <Company>()); context.Companies.Add(new AutoFaker <Company>()); context.SaveChanges(); } }
public static void SeedSampleOfficeData(VisitPopDbContext context) { if (!context.Offices.Any()) { context.Offices.Add(new AutoFaker <Office>()); context.Offices.Add(new AutoFaker <Office>()); context.Offices.Add(new AutoFaker <Office>()); context.Offices.Add(new AutoFaker <Office>()); context.SaveChanges(); } }
public static void SeedSampleObservacionData(VisitPopDbContext context) { if (!context.Observaciones.Any()) { context.Observaciones.Add(new AutoFaker <Observacion>()); context.Observaciones.Add(new AutoFaker <Observacion>()); context.Observaciones.Add(new AutoFaker <Observacion>()); context.Observaciones.Add(new AutoFaker <Observacion>()); context.SaveChanges(); } }
public static void SeedRegisterControlData(VisitPopDbContext context) { if (!context.RegisterControls.Any()) { context.RegisterControls.Add(new AutoFaker <RegisterControl>()); context.RegisterControls.Add(new AutoFaker <RegisterControl>()); context.RegisterControls.Add(new AutoFaker <RegisterControl>()); context.RegisterControls.Add(new AutoFaker <RegisterControl>()); context.RegisterControls.Add(new AutoFaker <RegisterControl>()); context.SaveChanges(); } }
public static void PersonSampleData(VisitPopDbContext context) { if (!context.Persons.Any()) { context.Persons.Add(new AutoFaker <Person>()); context.Persons.Add(new AutoFaker <Person>()); context.Persons.Add(new AutoFaker <Person>()); context.Persons.Add(new AutoFaker <Person>()); context.Persons.Add(new AutoFaker <Person>()); context.SaveChanges(); } }
public static void SeedSampleVisitData(VisitPopDbContext context) { if (!context.Visits.Any()) { context.Visits.Add(new AutoFaker <Visit>()); context.Visits.Add(new AutoFaker <Visit>()); context.Visits.Add(new AutoFaker <Visit>()); context.Visits.Add(new AutoFaker <Visit>()); context.Visits.Add(new AutoFaker <Visit>()); context.Visits.Add(new AutoFaker <Visit>()); context.Visits.Add(new AutoFaker <Visit>()); context.Visits.Add(new AutoFaker <Visit>()); context.Visits.Add(new AutoFaker <Visit>()); context.SaveChanges(); } }
public static void SeedSampleEmployeeData(VisitPopDbContext context) { if (!context.Employees.Any()) { context.Employees.Add(new AutoFaker <Employee>()); context.Employees.Add(new AutoFaker <Employee>()); context.Employees.Add(new AutoFaker <Employee>()); context.Employees.Add(new AutoFaker <Employee>()); context.Employees.Add(new AutoFaker <Employee>()); context.Employees.Add(new AutoFaker <Employee>()); context.Employees.Add(new AutoFaker <Employee>()); context.Employees.Add(new AutoFaker <Employee>()); context.Employees.Add(new AutoFaker <Employee>()); context.SaveChanges(); } }
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 void GetEmployeeDepartmentsAsync_ReturnExpectedPageSize() { //Arrange var dbOptions = new DbContextOptionsBuilder <VisitPopDbContext>() .UseInMemoryDatabase(databaseName: $"EmployeeDepartmentDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeEmployeeDepartmentOne = new FakeEmployeeDepartment { }.Ignore(d => d.Id).Generate(); fakeEmployeeDepartmentOne.Id = 1; var fakeEmployeeDepartmentTwo = new FakeEmployeeDepartment { }.Ignore(d => d.Id).Generate(); fakeEmployeeDepartmentTwo.Id = 2; var fakeEmployeeDepartmentThree = new FakeEmployeeDepartment { }.Ignore(d => d.Id).Generate(); fakeEmployeeDepartmentThree.Id = 3; //Act using (var context = new VisitPopDbContext(dbOptions)) { context.EmployeeDepartments.AddRange(fakeEmployeeDepartmentOne, fakeEmployeeDepartmentTwo, fakeEmployeeDepartmentThree); context.SaveChanges(); var service = new EmployeeDepartmentRepository(context, new SieveProcessor(sieveOptions)); var EmployeeDepartmentRepo = await service.GetEmployeeDepartmentsAsync(new EmployeeDepartmentParametersDto { PageSize = 2 }); //Assert EmployeeDepartmentRepo.Should() .NotBeEmpty() .And.HaveCount(2); EmployeeDepartmentRepo.Should().ContainEquivalentOf(fakeEmployeeDepartmentOne); EmployeeDepartmentRepo.Should().ContainEquivalentOf(fakeEmployeeDepartmentTwo); context.Database.EnsureDeleted(); } }
public async void GetEmployeesAsync_FilterEmployeeIdListWithExact() { //Arrange var dbOptions = new DbContextOptionsBuilder <VisitPopDbContext>() .UseInMemoryDatabase(databaseName: $"EmployeeDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeEmployeeOne = new FakeEmployee { }.Generate(); fakeEmployeeOne.Id = 1; var fakeEmployeeTwo = new FakeEmployee { }.Generate(); fakeEmployeeTwo.Id = 2; var fakeEmployeeThree = new FakeEmployee { }.Generate(); fakeEmployeeThree.Id = 3; //Act using (var context = new VisitPopDbContext(dbOptions)) { context.Employees.AddRange(fakeEmployeeOne, fakeEmployeeTwo, fakeEmployeeThree); context.SaveChanges(); var service = new EmployeeRepository(context, new SieveProcessor(sieveOptions)); var employeeRepo = await service.GetEmployeesAsync(new EmployeeParametersDto { Filters = $"Id == {fakeEmployeeTwo.Id}" }); //Assert employeeRepo.Should() .HaveCount(1); context.Database.EnsureDeleted(); } }
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 async void GetEmployeeDepartmentsAsync_FilterNameListWithExact() { //Arrange var dbOptions = new DbContextOptionsBuilder <VisitPopDbContext>() .UseInMemoryDatabase(databaseName: $"EmployeeDepartmentDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeEmployeeDepartmentOne = new FakeEmployeeDepartment { }.Generate(); fakeEmployeeDepartmentOne.Name = "alpha"; var fakeEmployeeDepartmentTwo = new FakeEmployeeDepartment { }.Generate(); fakeEmployeeDepartmentTwo.Name = "bravo"; var fakeEmployeeDepartmentThree = new FakeEmployeeDepartment { }.Generate(); fakeEmployeeDepartmentThree.Name = "charlie"; //Act using (var context = new VisitPopDbContext(dbOptions)) { context.EmployeeDepartments.AddRange(fakeEmployeeDepartmentOne, fakeEmployeeDepartmentTwo, fakeEmployeeDepartmentThree); context.SaveChanges(); var service = new EmployeeDepartmentRepository(context, new SieveProcessor(sieveOptions)); var EmployeeDepartmentRepo = await service.GetEmployeeDepartmentsAsync(new EmployeeDepartmentParametersDto { Filters = $"Name == {fakeEmployeeDepartmentTwo.Name}" }); //Assert EmployeeDepartmentRepo.Should() .HaveCount(1); context.Database.EnsureDeleted(); } }
public async void GetEmployeesAsync_ListEmailAddressSortedInDescOrder() { //Arrange var dbOptions = new DbContextOptionsBuilder <VisitPopDbContext>() .UseInMemoryDatabase(databaseName: $"EmployeeDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeEmployeeOne = new FakeEmployee { }.Generate(); fakeEmployeeOne.EmailAddress = "bravo"; var fakeEmployeeTwo = new FakeEmployee { }.Generate(); fakeEmployeeTwo.EmailAddress = "alpha"; var fakeEmployeeThree = new FakeEmployee { }.Generate(); fakeEmployeeThree.EmailAddress = "charlie"; //Act using (var context = new VisitPopDbContext(dbOptions)) { context.Employees.AddRange(fakeEmployeeOne, fakeEmployeeTwo, fakeEmployeeThree); context.SaveChanges(); var service = new EmployeeRepository(context, new SieveProcessor(sieveOptions)); var employeeRepo = await service.GetEmployeesAsync(new EmployeeParametersDto { SortOrder = "-EmailAddress" }); //Assert employeeRepo.Should() .ContainInOrder(fakeEmployeeThree, fakeEmployeeOne, fakeEmployeeTwo); context.Database.EnsureDeleted(); } }
public async void GetEmployeeDepartmentsAsync_ListEmployeeDepartmentIdSortedInDescOrder() { //Arrange var dbOptions = new DbContextOptionsBuilder <VisitPopDbContext>() .UseInMemoryDatabase(databaseName: $"EmployeeDepartmentDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeEmployeeDepartmentOne = new FakeEmployeeDepartment { }.Generate(); fakeEmployeeDepartmentOne.Id = 2; var fakeEmployeeDepartmentTwo = new FakeEmployeeDepartment { }.Generate(); fakeEmployeeDepartmentTwo.Id = 1; var fakeEmployeeDepartmentThree = new FakeEmployeeDepartment { }.Generate(); fakeEmployeeDepartmentThree.Id = 3; //Act using (var context = new VisitPopDbContext(dbOptions)) { context.EmployeeDepartments.AddRange(fakeEmployeeDepartmentOne, fakeEmployeeDepartmentTwo, fakeEmployeeDepartmentThree); context.SaveChanges(); var service = new EmployeeDepartmentRepository(context, new SieveProcessor(sieveOptions)); var EmployeeDepartmentRepo = await service.GetEmployeeDepartmentsAsync(new EmployeeDepartmentParametersDto { SortOrder = "-Id" }); //Assert EmployeeDepartmentRepo.Should() .ContainInOrder(fakeEmployeeDepartmentThree, fakeEmployeeDepartmentOne, fakeEmployeeDepartmentTwo); context.Database.EnsureDeleted(); } }
public void DeleteEmployee_ReturnsProperCount() { //Arrange var dbOptions = new DbContextOptionsBuilder <VisitPopDbContext>() .UseInMemoryDatabase(databaseName: $"EmployeeDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeEmployeeOne = new FakeEmployee { }.Generate(); var fakeEmployeeTwo = new FakeEmployee { }.Generate(); var fakeEmployeeThree = new FakeEmployee { }.Generate(); //Act using (var context = new VisitPopDbContext(dbOptions)) { context.Employees.AddRange(fakeEmployeeOne, fakeEmployeeTwo, fakeEmployeeThree); var service = new EmployeeRepository(context, new SieveProcessor(sieveOptions)); service.DeleteEmployee(fakeEmployeeTwo); context.SaveChanges(); //Assert var employeeList = context.Employees.ToList(); employeeList.Should() .NotBeEmpty() .And.HaveCount(2); employeeList.Should().ContainEquivalentOf(fakeEmployeeOne); employeeList.Should().ContainEquivalentOf(fakeEmployeeThree); Assert.DoesNotContain(employeeList, e => e == fakeEmployeeTwo); context.Database.EnsureDeleted(); } }
public async void GetEmployeesAsync_CountMatchesAndContainsEquivalentObjects() { //Arrange var dbOptions = new DbContextOptionsBuilder <VisitPopDbContext>() .UseInMemoryDatabase(databaseName: $"EmployeeDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeEmployeeOne = new FakeEmployee { }.Generate(); var fakeEmployeeTwo = new FakeEmployee { }.Generate(); var fakeEmployeeThree = new FakeEmployee { }.Generate(); //Act using (var context = new VisitPopDbContext(dbOptions)) { context.Employees.AddRange(fakeEmployeeOne, fakeEmployeeTwo, fakeEmployeeThree); context.SaveChanges(); var service = new EmployeeRepository(context, new SieveProcessor(sieveOptions)); var employeeRepo = await service.GetEmployeesAsync(new EmployeeParametersDto()); //Assert employeeRepo.Should() .NotBeEmpty() .And.HaveCount(3); employeeRepo.Should().ContainEquivalentOf(fakeEmployeeOne); employeeRepo.Should().ContainEquivalentOf(fakeEmployeeTwo); employeeRepo.Should().ContainEquivalentOf(fakeEmployeeThree); context.Database.EnsureDeleted(); } }