public async Task GetMobilePhoneById_InMemoryTest() { var serviceProvider = BuildInMemoryDBProvider(); using (var dbContext = serviceProvider.GetService <DatabaseContext>()) { //Arrange dbContext.Add(new MobilePhone() { Id = 1, Brand = "Apple", Name = "iPhone 12", Price = 3000, ShortDescription = "short", Description = "Description", ActiveStatus = true, QuantityInStack = QuantityStatus.Full, MainImage = "/Apple/iPhone 12/Main.png", FirstImage = "/Apple/iPhone 12/First.png", SecondImage = "/Apple/iPhone 12/Second.png", BestSeller = true, MultimediaId = 1 }); dbContext.Add(new MobilePhone() { Id = 4, Brand = "LG", Name = "Wing 5G", Price = 4500, ShortDescription = "short", Description = "Description", ActiveStatus = true, QuantityInStack = QuantityStatus.Full, MainImage = "/LG/Wing/Main.png", FirstImage = "/LG/Wing/First.png", SecondImage = "/LG/Wing/Second.png", BestSeller = true, MultimediaId = 1 }); dbContext.SaveChanges(); var mobilePhoneRepository = new MobilePhoneRepository(dbContext); //Act var result = await mobilePhoneRepository.GetMobilePhoneById(1); //Assert result.Brand.Should().Be("Apple"); result.Name.Should().Be("iPhone 12"); } }
public void GetBestSellers_EmptyDB() { var serviceProvider = BuildInMemoryDBProvider(); using (var dbContext = serviceProvider.GetService <DatabaseContext>()) { //Arrange var mobilePhoneRepository = new MobilePhoneRepository(dbContext); //Act var result = mobilePhoneRepository.GetBestSellers(); //Assert result.Should().BeEmpty(); } }
public void GetCameraVMTest() { var service = BuildInMemoryDBProvider(); using (var dbContext = service.GetService <DatabaseContext>()) { //Arrange var cameraiPhone12 = new Camera() { Id = 1, Zoom = 8, FrontResulution = 16, MainResulution = 32, AdditionalResulution = 16, VideoRecorderResolution = "4K", VideoFPS = 120, Functions = "Video Recorder;Autofokus;Flash", MobilePhoneId = 1 }; var iPhone12 = new MobilePhone() { Id = 1, Brand = "Apple", Name = "iPhone 12", Price = 3000, ShortDescription = "short", Description = "description", ActiveStatus = true, QuantityInStack = QuantityStatus.Full, MainImage = "/Apple/iPhone 12/Main.png", FirstImage = "/Apple/iPhone 12/First.png", SecondImage = "/Apple/iPhone 12/Second.png", Camera = cameraiPhone12, BestSeller = true }; var configuration = new MapperConfiguration(cfg => { cfg.CreateMap <Camera, CameraVM>(); }); var mapper = new Mapper(configuration); var mobilePhoneRepository = new MobilePhoneRepository(dbContext); var mobilePhoneService = new MobilePhoneService(mobilePhoneRepository, mapper); //Act var result = mobilePhoneService.GetCameraVM(iPhone12); //Assert result.Should().BeOfType <CameraVM>(); } }
public void GetHardwareVM() { var service = BuildInMemoryDBProvider(); using (var dbContext = service.GetService <DatabaseContext>()) { //Arrange var hardwareiPhone12 = new Hardware() { Id = 1, ProcessorName = "A14 Bionic", OperationSystem = "iOS", GraphicsProcessor = "A14 Bionic", OperationMemory = 4, MemorySpace = 64, SimCardType = "Nano", BatteryCapacity = 2500, MobilePhoneId = 1 }; var iPhone12 = new MobilePhone() { Id = 1, Brand = "Apple", Name = "iPhone 12", Price = 3000, ShortDescription = "short", Description = "description", ActiveStatus = true, QuantityInStack = QuantityStatus.Full, MainImage = "/Apple/iPhone 12/Main.png", FirstImage = "/Apple/iPhone 12/First.png", SecondImage = "/Apple/iPhone 12/Second.png", Hardware = hardwareiPhone12, BestSeller = true }; var configuration = new MapperConfiguration(cfg => { cfg.CreateMap <Hardware, HardwareVM>(); }); var mapper = new Mapper(configuration); var mobilePhoneRepository = new MobilePhoneRepository(dbContext); var mobilePhoneService = new MobilePhoneService(mobilePhoneRepository, mapper); //Act var result = mobilePhoneService.GetHardwareVM(iPhone12); //Assert result.Should().BeOfType <HardwareVM>(); } }
public async Task GetMobilePhoneById_EmptyDB() { var serviceProvider = BuildInMemoryDBProvider(); using (var dbContext = serviceProvider.GetService <DatabaseContext>()) { //Arrange var mobilePhoneRepository = new MobilePhoneRepository(dbContext); //Act var result = await mobilePhoneRepository.GetMobilePhoneById(2); //Assert result.Should().BeNull(); } }
public void GetMultimediaVM() { var service = BuildInMemoryDBProvider(); using (var dbContext = service.GetService <DatabaseContext>()) { //Arrange var multimediaApple = new Multimedia() { Id = 1, USBType = "Lighting", Bluetooth = true, NFC = true, FingerPrintReader = true, LTE = true, GPS = true, WiFiCalling = false }; var iPhone12 = new MobilePhone() { Id = 1, Brand = "Apple", Name = "iPhone 12", Price = 3000, ShortDescription = "short", Description = "description", ActiveStatus = true, QuantityInStack = QuantityStatus.Full, MainImage = "/Apple/iPhone 12/Main.png", FirstImage = "/Apple/iPhone 12/First.png", SecondImage = "/Apple/iPhone 12/Second.png", Multimedia = multimediaApple, BestSeller = true }; var configuration = new MapperConfiguration(cfg => { cfg.CreateMap <Multimedia, MultimediaVM>(); }); var mapper = new Mapper(configuration); var mobilePhoneRepository = new MobilePhoneRepository(dbContext); var mobilePhoneService = new MobilePhoneService(mobilePhoneRepository, mapper); //Act var result = mobilePhoneService.GetMultimediaVM(iPhone12); //Assert result.Should().BeOfType <MultimediaVM>(); } }
public void GetBestSellersTest() { var serviceProvider = BuildSqliteDBProvider(); using (var dbContext = serviceProvider.GetService <DatabaseContext>()) { //Arrange dbContext.Database.OpenConnection(); dbContext.Database.EnsureCreated(); var mobilePhoneRepository = new MobilePhoneRepository(dbContext); //Act var result = mobilePhoneRepository.GetBestSellers(); //Assert result.Should().HaveCount(3); } }
public void GetScreenVM() { var service = BuildInMemoryDBProvider(); using (var dbContext = service.GetService <DatabaseContext>()) { //Arrange var screeniPhone12 = new Screen() { Id = 1, Size = 6.1m, ColorsQuantity = 16, ScreenType = "OLED Super Retina XDR", HorizontalResolution = 2532, VerticalResolution = 1170, MobilePhoneId = 1 }; var iPhone12 = new MobilePhone() { Id = 1, Brand = "Apple", Name = "iPhone 12", Price = 3000, ShortDescription = "short", Description = "description", ActiveStatus = true, QuantityInStack = QuantityStatus.Full, MainImage = "/Apple/iPhone 12/Main.png", FirstImage = "/Apple/iPhone 12/First.png", SecondImage = "/Apple/iPhone 12/Second.png", Screen = screeniPhone12, BestSeller = true }; var configuration = new MapperConfiguration(cfg => { cfg.CreateMap <Screen, ScreenVM>(); }); var mapper = new Mapper(configuration); var mobilePhoneRepository = new MobilePhoneRepository(dbContext); var mobilePhoneService = new MobilePhoneService(mobilePhoneRepository, mapper); //Act var result = mobilePhoneService.GetScreenVM(iPhone12); //Assert result.Should().BeOfType <ScreenVM>(); } }
public async Task GetMobilePhoneByIdTestNoData() { var serviceProvider = BuildSqliteDBProvider(); using (var dbContext = serviceProvider.GetService <DatabaseContext>()) { //Arrange dbContext.Database.OpenConnection(); dbContext.Database.EnsureCreated(); var mobilePhoneRepository = new MobilePhoneRepository(dbContext); //Act var result = await mobilePhoneRepository.GetMobilePhoneById(31); //Assert result.Should().BeNull(); } }
public void RetriveFilteredMobilePhonesTest_FiltredByMemorySpace() { var serviceProvider = BuildSqliteDBProvider(); using (var dbContext = serviceProvider.GetService <DatabaseContext>()) { //Arrange var filters = new Filters(); filters.MemorySpace = 256; dbContext.Database.OpenConnection(); dbContext.Database.EnsureCreated(); var mobilePhoneRepository = new MobilePhoneRepository(dbContext); //Act var result = mobilePhoneRepository.RetriveFilteredMobilePhones(filters); //Assert result.Should().HaveCount(8); } }
public void RetriveFilteredMobilePhonesTest_RetriveAppleAndSony() { var serviceProvider = BuildSqliteDBProvider(); using (var dbContext = serviceProvider.GetService <DatabaseContext>()) { //Arrange var filters = new Filters(); filters.Brands.Apple = true; filters.Brands.Sony = true; dbContext.Database.OpenConnection(); dbContext.Database.EnsureCreated(); var mobilePhoneRepository = new MobilePhoneRepository(dbContext); //Act var result = mobilePhoneRepository.RetriveFilteredMobilePhones(filters); //Assert result.Should().HaveCount(7); } }
public async Task GetMobilePhonesForHomeTest_DBEmpty() { var service = BuildInMemoryDBProvider(); using (var dbContext = service.GetService <DatabaseContext>()) { var configuration = new MapperConfiguration(cfg => { cfg.CreateMap <MobilePhone, MobilePhoneForHomeVM>(); }); //Arrange var mapper = new Mapper(configuration); var mobilePhoneRepository = new MobilePhoneRepository(dbContext); var mobilePhoneService = new MobilePhoneService(mobilePhoneRepository, mapper); //Act var result = await mobilePhoneService.GetMobilePhonesForHome(); //Assert result.Should().HaveCount(0); } }
public void RetriveFilteredMobilePhonesTest_WithManyFiltersSecondTest() { var serviceProvider = BuildSqliteDBProvider(); using (var dbContext = serviceProvider.GetService <DatabaseContext>()) { //Arrange var filters = new Filters(); filters.OperationMemory = 8; filters.MemorySpace = 64; filters.MinPrice = 2000; filters.MaxPrice = 4000; dbContext.Database.OpenConnection(); dbContext.Database.EnsureCreated(); var mobilePhoneRepository = new MobilePhoneRepository(dbContext); //Act var result = mobilePhoneRepository.RetriveFilteredMobilePhones(filters); //Assert result.Should().HaveCount(4); } }
public async Task GetMobilePhoneDetailsTest_EmptyDb() { var service = BuildInMemoryDBProvider(); using (var dbContext = service.GetService <DatabaseContext>()) { //Arrange var configuration = new MapperConfiguration(cfg => { cfg.CreateMap <MobilePhone, MobilePhoneDetailsVM>(); }); var mapper = new Mapper(configuration); var mobilePhoneRepository = new MobilePhoneRepository(dbContext); var mobilePhoneService = new MobilePhoneService(mobilePhoneRepository, mapper); //Act var result = await mobilePhoneService.GetMobilePhoneDetails(1); //Assert result.Should().BeNull(); } }
public async Task GetMobilePhoneDetailsTest_ShouldGetAnObject() { var service = BuildInMemoryDBProvider(); using (var dbContext = service.GetService <DatabaseContext>()) { //Arrange var iPhone12 = new MobilePhone() { Id = 1, Brand = "Apple", Name = "iPhone 12", Price = 3000, ShortDescription = "short", Description = "Description", ActiveStatus = true, QuantityInStack = QuantityStatus.Full, MainImage = "/Apple/iPhone 12/Main.png", FirstImage = "/Apple/iPhone 12/First.png", SecondImage = "/Apple/iPhone 12/Second.png", BestSeller = true }; dbContext.Add(iPhone12); dbContext.SaveChanges(); var configuration = new MapperConfiguration(cfg => { cfg.CreateMap <MobilePhone, MobilePhoneDetailsVM>(); }); var mapper = new Mapper(configuration); var mobilePhoneRepository = new MobilePhoneRepository(dbContext); var mobilePhoneService = new MobilePhoneService(mobilePhoneRepository, mapper); //Act var result = await mobilePhoneService.GetMobilePhoneDetails(1); //Assert result.Should().BeOfType <MobilePhoneDetailsVM>(); } }
public async Task GetMobilePhoneByIdTest() { var serviceProvider = BuildSqliteDBProvider(); using (var dbContext = serviceProvider.GetService <DatabaseContext>()) { //Arrange dbContext.Database.OpenConnection(); dbContext.Database.EnsureCreated(); var mobilePhoneRepository = new MobilePhoneRepository(dbContext); //Act var result = await mobilePhoneRepository.GetMobilePhoneById(1); //Assert result.Brand.Should().Be("Apple"); result.Name.Should().Be("iPhone 12"); result.Multimedia.Id.Should().Be(1); result.Camera.Id.Should().Be(1); result.Hardware.Id.Should().Be(1); result.Screen.Id.Should().Be(1); } }
public void GetScreenVM_Null() { var service = BuildInMemoryDBProvider(); using (var dbContext = service.GetService <DatabaseContext>()) { //Arrange var iPhone12 = new MobilePhone() { Id = 1, Brand = "Apple", Name = "iPhone 12", Price = 3000, ShortDescription = "short", Description = "description", ActiveStatus = true, QuantityInStack = QuantityStatus.Full, MainImage = "/Apple/iPhone 12/Main.png", FirstImage = "/Apple/iPhone 12/First.png", SecondImage = "/Apple/iPhone 12/Second.png", BestSeller = true }; var configuration = new MapperConfiguration(cfg => { cfg.CreateMap <Screen, ScreenVM>(); }); var mapper = new Mapper(configuration); var mobilePhoneRepository = new MobilePhoneRepository(dbContext); var mobilePhoneService = new MobilePhoneService(mobilePhoneRepository, mapper); //Act var result = mobilePhoneService.GetScreenVM(iPhone12); //Assert result.Should().BeNull(); } }
public void RetriveFilteredMobilePhonesTest_WithManyFiltersThirdTest() { var serviceProvider = BuildSqliteDBProvider(); using (var dbContext = serviceProvider.GetService <DatabaseContext>()) { //Arrange var filters = new Filters(); filters.OperationMemory = 6; filters.MemorySpace = 32; filters.Brands.Apple = true; filters.Brands.Xiaomi = true; filters.Brands.Nokia = true; filters.Brands.Motorola = true; filters.MaxPrice = 3000; dbContext.Database.OpenConnection(); dbContext.Database.EnsureCreated(); var mobilePhoneRepository = new MobilePhoneRepository(dbContext); //Act var result = mobilePhoneRepository.RetriveFilteredMobilePhones(filters); //Assert result.Should().HaveCount(3); } }
public void GetBestSellers_ThereAreTwo() { var serviceProvider = BuildInMemoryDBProvider(); using (var dbContext = serviceProvider.GetService <DatabaseContext>()) { //Arrange dbContext.Add(new MobilePhone() { Id = 1, Brand = "Apple", Name = "iPhone 12", Price = 3000, ShortDescription = "short", Description = "Description", ActiveStatus = true, QuantityInStack = QuantityStatus.Full, MainImage = "/Apple/iPhone 12/Main.png", FirstImage = "/Apple/iPhone 12/First.png", SecondImage = "/Apple/iPhone 12/Second.png", BestSeller = true }); dbContext.Add(new MobilePhone() { Id = 4, Brand = "LG", Name = "Wing 5G", Price = 4500, ShortDescription = "short", Description = "Description", ActiveStatus = true, QuantityInStack = QuantityStatus.Full, MainImage = "/LG/Wing/Main.png", FirstImage = "/LG/Wing/First.png", SecondImage = "/LG/Wing/Second.png", BestSeller = true }); dbContext.Add(new MobilePhone() { Id = 24, Brand = "Apple", Name = "iPhone SE", Price = 2100, ShortDescription = "short", Description = "Description", ActiveStatus = false, QuantityInStack = QuantityStatus.Full, MainImage = "/Apple/iPhone SE/Main.png", FirstImage = "/Apple/iPhone SE/First.png", SecondImage = "/Apple/iPhone SE/Second.png", BestSeller = false }); dbContext.SaveChanges(); var mobilePhoneRepository = new MobilePhoneRepository(dbContext); //Act var result = mobilePhoneRepository.GetBestSellers(); //Assert result.Should().HaveCount(2); } }
public async Task GetMobilePhonesForHomeTest_ShouldGetThreeObjects() { var service = BuildInMemoryDBProvider(); using (var dbContext = service.GetService <DatabaseContext>()) { //Arrange dbContext.Add(new MobilePhone() { Id = 1, Brand = "Apple", Name = "iPhone 12", Price = 3000, ShortDescription = "short", Description = "Description", ActiveStatus = true, QuantityInStack = QuantityStatus.Full, MainImage = "/Apple/iPhone 12/Main.png", FirstImage = "/Apple/iPhone 12/First.png", SecondImage = "/Apple/iPhone 12/Second.png", BestSeller = true }); dbContext.Add(new MobilePhone() { Id = 4, Brand = "LG", Name = "Wing 5G", Price = 4500, ShortDescription = "short", Description = "Description", ActiveStatus = true, QuantityInStack = QuantityStatus.Full, MainImage = "/LG/Wing/Main.png", FirstImage = "/LG/Wing/First.png", SecondImage = "/LG/Wing/Second.png", BestSeller = true }); dbContext.Add(new MobilePhone() { Id = 24, Brand = "Apple", Name = "iPhone SE", Price = 2100, ShortDescription = "short", Description = "Description", ActiveStatus = true, QuantityInStack = QuantityStatus.Full, MainImage = "/Apple/iPhone SE/Main.png", FirstImage = "/Apple/iPhone SE/First.png", SecondImage = "/Apple/iPhone SE/Second.png", BestSeller = true }); dbContext.SaveChanges(); var configuration = new MapperConfiguration(cfg => { cfg.CreateMap <MobilePhone, MobilePhoneForHomeVM>(); }); var mapper = new Mapper(configuration); var mobilePhoneRepository = new MobilePhoneRepository(dbContext); var mobilePhoneService = new MobilePhoneService(mobilePhoneRepository, mapper); //Act var result = await mobilePhoneService.GetMobilePhonesForHome(); //Assert result.Should().HaveCount(3); result.Should().BeOfType <List <MobilePhoneForHomeVM> >(); } }
public async Task GetFilteredMobilePhonesTest_ShouldGetOneObjectsWithIOS() { var service = BuildInMemoryDBProvider(); using (var dbContext = service.GetService <DatabaseContext>()) { //Arrange var hardwareiPhone12 = new Hardware() { Id = 1, ProcessorName = "A14 Bionic", OperationSystem = "iOS", GraphicsProcessor = "A14 Bionic", OperationMemory = 4, MemorySpace = 64, SimCardType = "Nano", BatteryCapacity = 2500, MobilePhoneId = 1 }; dbContext.Add(new MobilePhone() { Id = 1, Brand = "Apple", Name = "iPhone 12", Price = 3000, ShortDescription = "short", Description = "Description", ActiveStatus = true, QuantityInStack = QuantityStatus.Full, MainImage = "/Apple/iPhone 12/Main.png", FirstImage = "/Apple/iPhone 12/First.png", SecondImage = "/Apple/iPhone 12/Second.png", BestSeller = true, Hardware = new Hardware() { Id = 1, OperationSystem = "iOS", MobilePhoneId = 1 } }); dbContext.Add(new MobilePhone() { Id = 4, Brand = "LG", Name = "Wing 5G", Price = 4500, ShortDescription = "short", Description = "Description", ActiveStatus = true, QuantityInStack = QuantityStatus.Full, MainImage = "/LG/Wing/Main.png", FirstImage = "/LG/Wing/First.png", SecondImage = "/LG/Wing/Second.png", BestSeller = true, Hardware = new Hardware() { Id = 2, OperationSystem = "Android", MobilePhoneId = 4 } }); dbContext.Add(new MobilePhone() { Id = 24, Brand = "Apple", Name = "iPhone SE", Price = 2100, ShortDescription = "short", Description = "Description", ActiveStatus = true, QuantityInStack = QuantityStatus.Full, MainImage = "/Apple/iPhone SE/Main.png", FirstImage = "/Apple/iPhone SE/First.png", SecondImage = "/Apple/iPhone SE/Second.png", BestSeller = true, Hardware = new Hardware() { Id = 3, OperationSystem = "Android", MobilePhoneId = 24 } }); dbContext.SaveChanges(); var configuration = new MapperConfiguration(cfg => { cfg.CreateMap <MobilePhone, MobilePhoneForListVM>(); }); var mapper = new Mapper(configuration); var mobilePhoneRepository = new MobilePhoneRepository(dbContext); var mobilePhoneService = new MobilePhoneService(mobilePhoneRepository, mapper); var filters = new Filters(); filters.OperationSystem = "iOS"; //Act var result = await mobilePhoneService.GetFilteredMobilePhones(filters); //Assert result.Should().HaveCount(1); result.Should().BeOfType <List <MobilePhoneForListVM> >(); } }