Пример #1
0
        public async Task GetAllTyres_WithDummyData_ShouldReturnCorrectResults()
        {
            string errorMessagePrefix = "TyreService GetAllTyress() method does not work properly.";

            var context = SntDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.tyreService = new TyreService(context);

            List <TyreServiceModel> actualResults = await this.tyreService.GetAllTyres().ToListAsync();

            List <TyreServiceModel> expectedResults = GetDummyData().To <TyreServiceModel>().ToList();

            for (int i = 0; i < expectedResults.Count; i++)
            {
                var expectedEntry = expectedResults[i];
                var actualEntry   = actualResults[i];

                Assert.True(expectedEntry.Model == actualEntry.Model, errorMessagePrefix + " " + "Model is not returned properly.");
                Assert.True(expectedEntry.Brand == actualEntry.Brand, errorMessagePrefix + " " + "Brand is not returned properly.");
                Assert.True(expectedEntry.Type == actualEntry.Type, errorMessagePrefix + " " + "Type is not returned properly.");
                Assert.True(expectedEntry.Status == actualEntry.Status, errorMessagePrefix + " " + "Status is not returned properly.");
                Assert.True(expectedEntry.Diameter == actualEntry.Diameter, errorMessagePrefix + " " + "Diameter is not returned properly.");
                Assert.True(expectedEntry.Ratio == actualEntry.Ratio, errorMessagePrefix + " " + "Ratio is not returned properly.");
                Assert.True(expectedEntry.Description == actualEntry.Description, errorMessagePrefix + " " + "Description is not returned properly.");
                Assert.True(expectedEntry.Width == actualEntry.Width, errorMessagePrefix + " " + "Width is not returned properly.");
                Assert.True(expectedEntry.YearOfProduction == actualEntry.YearOfProduction, errorMessagePrefix + " " + "YearOfProduction is not returned properly.");
                Assert.True(expectedEntry.Price == actualEntry.Price, errorMessagePrefix + " " + "Price is not returned properly.");
                Assert.True(expectedEntry.Picture == actualEntry.Picture, errorMessagePrefix + " " + "Picture is not returned properly.");
            }
        }
Пример #2
0
        public async Task GetTyreById_WithExistentId_ShouldReturnCorrectResult()
        {
            string errorMessagePrefix = "TyreService GetTyreById() method does not work properly.";

            var context = SntDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.tyreService = new TyreService(context);

            TyreServiceModel expectedData = context.Tyres.First().To <TyreServiceModel>();
            TyreServiceModel actualData   = this.tyreService.GetTyreById(expectedData.Id);

            Assert.True(expectedData.Model == actualData.Model, errorMessagePrefix + " " + "Model is not returned properly.");
            Assert.True(expectedData.Brand == actualData.Brand, errorMessagePrefix + " " + "Brand is not returned properly.");
            Assert.True(expectedData.Type == actualData.Type, errorMessagePrefix + " " + "Type is not returned properly.");
            Assert.True(expectedData.Status == actualData.Status, errorMessagePrefix + " " + "Status is not returned properly.");
            Assert.True(expectedData.Diameter == actualData.Diameter, errorMessagePrefix + " " + "Diameter is not returned properly.");
            Assert.True(expectedData.Ratio == actualData.Ratio, errorMessagePrefix + " " + "Ratio is not returned properly.");
            Assert.True(expectedData.Description == actualData.Description, errorMessagePrefix + " " + "Description is not returned properly.");
            Assert.True(expectedData.Width == actualData.Width, errorMessagePrefix + " " + "Width is not returned properly.");
            Assert.True(expectedData.YearOfProduction == actualData.YearOfProduction, errorMessagePrefix + " " + "YearOfProduction is not returned properly.");
            Assert.True(expectedData.Price == actualData.Price, errorMessagePrefix + " " + "Price is not returned properly.");
            Assert.True(expectedData.Picture == actualData.Picture, errorMessagePrefix + " " + "Picture is not returned properly.");
        }
Пример #3
0
        public async Task EditTyre_WithCorrectData_ShouldEditProductCorrectly()
        {
            string errorMessagePrefix = "TyreService EditTyre() method does not work properly.";

            var context = SntDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.tyreService = new TyreService(context);

            TyreServiceModel expectedData = context.Tyres.First().To <TyreServiceModel>();

            expectedData.Model            = "EdittedModelame";
            expectedData.Price            = 0.01M;
            expectedData.YearOfProduction = 1998;
            expectedData.Picture          = "Editted_Picture";

            await this.tyreService.EditTyre(expectedData);

            TyreServiceModel actualData = context.Tyres.First().To <TyreServiceModel>();

            Assert.True(actualData.Model == expectedData.Model, errorMessagePrefix + " " + "Model not editted properly.");
            Assert.True(actualData.Price == expectedData.Price, errorMessagePrefix + " " + "Price not editted properly.");
            Assert.True(actualData.YearOfProduction == expectedData.YearOfProduction, errorMessagePrefix + " " + "YearOfProduction not editted properly.");
            Assert.True(actualData.Picture == expectedData.Picture, errorMessagePrefix + " " + "Picture not editted properly.");
        }
Пример #4
0
 public HomeController(ITyreService tyreService, IWheelRimService wheelRimService,
                       IMotorOilService motorOilService)
 {
     this.tyreService     = tyreService;
     this.wheelRimService = wheelRimService;
     this.motorOilService = motorOilService;
 }
Пример #5
0
        public async Task Create_WithCorrectData_ShouldSuccessfullyCreate()
        {
            string errorMessagePrefix = "TyreService Create() method does not work properly.";

            var context = SntDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.tyreService = new TyreService(context);

            TyreServiceModel testProduct = new TyreServiceModel
            {
                Model            = "Giant Ant",
                Brand            = "Pym Tech",
                Type             = Models.Enums.SeasonType.AllSeasons,
                Price            = 189.59M,
                YearOfProduction = 2018,
                Picture          = "src/pics/giant/ant",
                Width            = 195,
                Ratio            = 65,
                Diameter         = 15,
                Status           = Models.Enums.AvailabilityStatus.OutOfStock,
                Description      = "Wield the power of Giant Ant!"
            };

            bool actualResult = await this.tyreService.Create(testProduct);

            Assert.True(actualResult, errorMessagePrefix);
        }
Пример #6
0
 public TyreController(ITyreService tyreService, IOrderService orderService,
                       UserManager <SntUser> userManager, IShoppingBagService shoppingbagService)
 {
     this.tyreService        = tyreService;
     this.orderService       = orderService;
     this.userManager        = userManager;
     this.shoppingbagService = shoppingbagService;
 }
Пример #7
0
        public async Task GetAllAvailableTyres_WithZeroData_ShouldReturnEmptyResults()
        {
            string errorMessagePrefix = "TyreService GetAllAvailableTyres() method does not work properly.";

            var context = SntDbContextInMemoryFactory.InitializeContext();

            this.tyreService = new TyreService(context);

            List <TyreServiceModel> actualResults = await this.tyreService.GetAllAvailableTyres().ToListAsync();

            Assert.True(actualResults.Count == 0, errorMessagePrefix);
        }
Пример #8
0
        public async Task GetTyreById_WithNonExistentId_ShouldReturnNull()
        {
            string errorMessagePrefix = "TyreService GetTyreById() method does not work properly.";

            var context = SntDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.tyreService = new TyreService(context);

            TyreServiceModel actualData = this.tyreService.GetTyreById("stamat");

            Assert.True(actualData == null, errorMessagePrefix);
        }
Пример #9
0
        public async Task GivenTyreService_WhenGetAllTyresIsCalled_ThenRepositoryIsCalled()
        {
            //Arrange
            var tyres = GetSampleTyres();

            _mockTyreRepository.Setup(x => x.GetAllTyres()).ReturnsAsync(tyres);
            _tyreService = new TyreService(_mockTyreRepository.Object);

            //Act
            await _tyreService.GetAllTyres();

            //Assert
            _mockTyreRepository.Verify(x => x.GetAllTyres(), Times.AtLeastOnce);
        }
Пример #10
0
        public async Task GivenTyreService_WhenGetAllTyresIsCalled_ThenReturnListTyres()
        {
            //Arrange
            var expected = GetSampleTyres();

            _mockTyreRepository.Setup(x => x.GetAllTyres()).ReturnsAsync(expected);
            _tyreService = new TyreService(_mockTyreRepository.Object);

            //Act
            var result = await _tyreService.GetAllTyres();

            //Assert
            Assert.IsInstanceOf <IEnumerable <Tyre> >(result);
            Assert.AreEqual(expected.Count(), result.Count());
        }
Пример #11
0
        public async Task EditTyre_WithCorrectData_ShouldPassSuccessfully()
        {
            string errorMessagePrefix = "TyreService Edit() method does not work properly.";

            var context = SntDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.tyreService = new TyreService(context);

            TyreServiceModel expectedData = context.Tyres.First().To <TyreServiceModel>();

            bool actualData = await this.tyreService.EditTyre(expectedData);

            Assert.True(actualData, errorMessagePrefix);
        }
Пример #12
0
        public SelectVehicalViewModel
            (IMvxLogProvider logProvider,
            IMvxNavigationService navigationService,
            IOrderService orderService,
            ITyreService tyreService) :
            base(logProvider, navigationService)
        {
            _tyreService = tyreService;

            _selectedMake        = new ValidatableObject <Make>();
            _selectedModel       = new ValidatableObject <Model>();
            _selectedYear        = new ValidatableObject <Years>();
            _selectedTyre        = new ValidatableObject <Wheel>();
            _selectedVehicleTrim = new ValidatableObject <VehicleTrim>();

            AddValidations();
        }
Пример #13
0
        public async Task EditTyre_WithNonExistentTyreId_ShouldThrowArgumentNullException()
        {
            string errorMessagePrefix = "TyreService EditTyre() method does not work properly.";

            var context = SntDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.tyreService = new TyreService(context);

            TyreServiceModel expectedData = context.Tyres.First().To <TyreServiceModel>();


            expectedData.Id               = "1";
            expectedData.Model            = "EdittedModelame";
            expectedData.Price            = 0.01M;
            expectedData.YearOfProduction = 1998;
            expectedData.Picture          = "Editted_Picture";

            await Assert.ThrowsAsync <ArgumentNullException>(() => this.tyreService.EditTyre(expectedData));
        }
Пример #14
0
        public async Task GivenAllTyres_ItShouldOrder_AmountByAscending()
        {
            //Arrange
            var tyres = GetSampleTyres();

            _mockTyreRepository.Setup(x => x.GetAllTyres()).ReturnsAsync(tyres);
            _tyreService = new TyreService(_mockTyreRepository.Object);

            //Act
            var result = await _tyreService.GetAllTyres();

            //Assert
            const int expectedFirstItemId  = 1;
            const int expectedSecondItemId = 3;
            const int expectedThirdItemId  = 2;
            var       enumerable           = result as Tyre[] ?? result.ToArray();

            Assert.AreEqual(expectedFirstItemId, enumerable.First().Id);
            Assert.AreEqual(expectedSecondItemId, enumerable.ElementAt(1).Id);
            Assert.AreEqual(expectedThirdItemId, enumerable.ElementAt(2).Id);
        }
Пример #15
0
        public TestingViewModel(IMvxLogProvider logProvider,
                                IMvxNavigationService navigationService,
                                ITyreService tyreService, IAddressService addressService)
            : base(logProvider, navigationService)
        {
            _tyreService    = tyreService;
            _addressService = addressService;
            Button1Command  = new MvxCommand(async() => await Button1Execute());
            Button2Command  = new MvxCommand(async() => await Button2Execute());
            Button3Command  = new MvxCommand(async() => await Button3Execute());
            Button4Command  = new MvxCommand(async() => await Button4Execute());
            Button5Command  = new MvxCommand(async() => await Button5Execute());
            Button6Command  = new MvxCommand(async() => await Button6Execute());

            Address = new Address
            {
                UserId         = Guid.NewGuid(),
                PrimaryAddress = true,
                Postcode       = "G23 5HU",
                Street         = "Smith Street",
                City           = "Large City",
                PhoneNumber    = "115151"
            };
        }
Пример #16
0
 public TyresController(IWheelsShopData data, ITyreService service)
     : base(data)
 {
     this.service = service;
 }
Пример #17
0
 public TyreController(ITyreService tyreService, IMemoryCache memoryCache)
 {
     this.tyreService = tyreService;
     this.memoryCache = memoryCache;
 }
Пример #18
0
 public TyreController(ITyreService tyreService, ICloudinaryService cloudinaryService)
 {
     this.tyreService       = tyreService;
     this.cloudinaryService = cloudinaryService;
 }
Пример #19
0
 public VendorController(IOrderService vendorService, ITyreService tyreService)
 {
     this.vendorService = vendorService;
     this.tyreService   = tyreService;
 }
Пример #20
0
 public TyreController(ITyreService tyreService)
 {
     _tyreService = tyreService;
 }