public void ChangePrice_Test()
        {
            _contr.ChangePrice(2, 2.99m);

            Assert.IsNotNull(Storage.products[2].Price);
            Assert.AreEqual(2.99m, Storage.products[2].Price);
        }
Example #2
0
        public async Task Should_ChangePriceProduct_Returns200()
        {
            //arrange
            var command        = GetCreateProductCommand();
            var createdProduct = await CreateProductAsync(command);

            //act
            var priceArgument = createdProduct.Price + 50;
            var path          = ProductController.ChangePrice(createdProduct.Id, (int)priceArgument);
            var putResponse   = await Client.PutAsJsonAsync(path, new{});

            var getResponse = await GetProductAsync(createdProduct.Id);

            var stringResult = await getResponse.Content.ReadAsStringAsync();

            var responseProduct = JsonConvert.DeserializeObject <ProductViewModel>(stringResult);

            //assert
            putResponse.StatusCode.Should().Be(HttpStatusCode.OK);
            getResponse.StatusCode.Should().Be(HttpStatusCode.OK);

            command.Should().NotBeNull();
            command.Name.Should().Be(createdProduct.Name);
            command.Description.Should().Be(createdProduct.Description);
            command.BarCode.Should().Be(createdProduct.BarCode);
            command.Price.Should().NotBe(priceArgument);
            command.Dimensions.Should().Be(createdProduct.Dimensions);
            command.ManufacturerId.Should().Be(createdProduct.ManufacturerId);

            responseProduct.Id.Should().Be(createdProduct.Id);
            responseProduct.Name.Should().Be(createdProduct.Name);
            responseProduct.Description.Should().Be(createdProduct.Description);
            responseProduct.BarCode.Should().Be(createdProduct.BarCode);
            responseProduct.Price.Should().Be(priceArgument);
            responseProduct.Dimensions.Should().Be(createdProduct.Dimensions);
            responseProduct.ManufacturerId.Should().Be(createdProduct.ManufacturerId);
            responseProduct.IsPublished.Should().BeFalse();
        }