예제 #1
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.");
        }
예제 #2
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);
        }
예제 #3
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.");
        }
예제 #4
0
        public async Task <bool> Create(TyreServiceModel tyreServiceModel)
        {
            Tyre tyre = AutoMapper.Mapper.Map <Tyre>(tyreServiceModel);

            context.Tyres.Add(tyre);
            int result = await context.SaveChangesAsync();

            return(result > 0);
        }
예제 #5
0
        public async Task <bool> EditTyre(TyreServiceModel tyreServiceModel)
        {
            var tyreFromDb = await this.context.Tyres.SingleOrDefaultAsync(p => p.Id == tyreServiceModel.Id);

            AutoMapper.Mapper.Map(tyreServiceModel, tyreFromDb);

            this.context.Tyres.Update(tyreFromDb);

            var result = await this.context.SaveChangesAsync();

            return(result > 0);
        }
예제 #6
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);
        }
예제 #7
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);
        }
예제 #8
0
        public async Task <IActionResult> Create(TyreCreateInputModel tyreCreateInputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(tyreCreateInputModel));
            }

            string imageUrl = await this.cloudinaryService.UploadPictureAsync(
                tyreCreateInputModel.Picture,
                tyreCreateInputModel.Model);

            TyreServiceModel tyreServiceModel = AutoMapper.Mapper.Map <TyreServiceModel>(tyreCreateInputModel);

            tyreServiceModel.Picture = imageUrl;

            await this.tyreService.Create(tyreServiceModel);

            return(this.Redirect("/"));
        }
예제 #9
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));
        }
예제 #10
0
        public async Task <IActionResult> Edit(TyreServiceModel tyreServiceModel)
        {
            await this.tyreService.EditTyre(tyreServiceModel);

            return(this.Redirect("/Administration/Tyre/AllTyres"));
        }