public async void GetProductByIdReturnsSingleProduct()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new ProductsController(context, _mapper))
                {
                    var result = await controller.GetProduct(3);

                    var okObjectResult = Assert.IsType <OkObjectResult>(result);
                    var resultValue    = okObjectResult.Value;

                    ProductDto p3 = GetTestProductDto(3);

                    Assert.NotNull(resultValue);
                    Assert.IsType <ProductDto>(resultValue);
                    ProductDto p = (ProductDto)resultValue;
                    Assert.True(p.Equals(p3));
                    Assert.True(p.Equals(p3, true));
                }
        }
        public void ProductProperlyMappedToProductDto()
        {
            ProductDto pDto1 = new ProductDto
            {
                Id        = 1,
                Alias     = "ALIAS",
                FullName  = "Great Product",
                ShortName = "GP"
            };
            Product p1 = new Product
            {
                Id        = 1,
                Alias     = "ALIAS",
                FullName  = "Great Product",
                ShortName = "GP"
            };

            ProductDto pDto2 = _mapper.Map <ProductDto>(p1);

            Assert.NotNull(pDto2);
            Assert.True(pDto1.Equals(pDto2));
            Assert.True(pDto1.Equals(pDto2, true));
        }
        public void GetProductsReturnsListOfAuthors()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new ProductsController(context, _mapper))
                {
                    var        result = controller.GetProducts();
                    ProductDto p3     = GetTestProductDto(3);

                    Assert.NotNull(result);

                    var okObjectResult = Assert.IsType <OkObjectResult>(result);
                    var resultValue    = okObjectResult.Value;
                    Assert.IsAssignableFrom <IEnumerable <ProductDto> >(resultValue);
                    Assert.NotEmpty((IEnumerable <ProductDto>)resultValue);

                    IEnumerable <ProductDto> resultValueList = (IEnumerable <ProductDto>)resultValue;

                    Assert.Equal(10, resultValueList.Count());
                    ProductDto p = (ProductDto)resultValueList.Where(r => r.Id == 3).FirstOrDefault();
                    Assert.True(p.Equals(p3));
                    Assert.True(p.Equals(p3, true));
                }
        }
        public void ProductDtoEqualsReturnsCorrectValues()
        {
            ProductDto p1 = new ProductDto
            {
                Id        = 1,
                Alias     = "ALIAS",
                FullName  = "Great Product",
                ShortName = "GP"
            };
            ProductDto p2 = new ProductDto
            {
                Id        = 1,
                Alias     = "ALIAS",
                FullName  = "Great Product",
                ShortName = "GP"
            };
            ProductDto p3 = new ProductDto
            {
                Id        = 3,
                Alias     = "ALIAS",
                FullName  = "Great Product",
                ShortName = "GP"
            };
            ProductDto p4 = new ProductDto
            {
                Id        = 1,
                Alias     = "SALIA",
                FullName  = "Bad Product",
                ShortName = "BP"
            };

            Assert.True(p1.Equals(p2));
            Assert.True(p1.Equals(p2, true));
            Assert.False(p1.Equals(p3));
            Assert.False(p1.Equals(p3, true));
            Assert.True(p1.Equals(p4));
            Assert.False(p1.Equals(p4, true));
        }