Example #1
0
        public void RemoveProductWhenObjectDoesnotExistsIn()
        {
            //Arrange
            var targetGood = new Good()
            {
                Price = 12.2m, Supplier = new Supplier()
                {
                    Name = "Maxim"
                }
            };
            var map = new Dictionary <string, IProduct>(new List <KeyValuePair <string, IProduct> >
            {
                new KeyValuePair <string, IProduct>("cart_list_1", new Good()),
            });
            var expected = map;

            var context = FakeHttpContext.NewFakeHttpContext();

            context.SetupProperty(e => e.Session, FakeHttpContext.FakeSession(map).Object);
            var cart = new Cart(context.Object);

            //Actual
            cart.Remove(targetGood);
            //Assert
            NAssert.AreEqual(expected, map);
        }
Example #2
0
            public void AddProduct_WhenSessionIsNotClear_ResultAdd2ProductsToCart()
            {
                //Arrange
                var map = new Dictionary <string, IProduct>(new List <KeyValuePair <string, IProduct> >
                {
                    new KeyValuePair <string, IProduct>("cart_list_0", new Good()),
                    new KeyValuePair <string, IProduct>("cart_list_1", new Good()),
                    new KeyValuePair <string, IProduct>("cart_list_2", new Good()),
                });


                ICollection <IProduct> collection = new List <IProduct>((IEnumerable <IProduct>) new[]
                {
                    new Good(),
                    new Good()
                });

                var context = FakeHttpContext.NewFakeHttpContext();

                context.SetupProperty(e => e.Session, FakeHttpContext.FakeSession(map).Object);
                var cart = new Cart(context.Object);

                //Actual
                cart.AddProduct(collection.ToArray());
                //Assert
                Assert.Equal(map.Count, cart.AmountProducts());
            }
Example #3
0
            public void GetAllProductsWhenOnesAreNotClear()
            {
                //Arrange
                var expectedList = new[]
                {
                    new Good(),
                    new Good()
                };
                var listObjects = new List <KeyValuePair <string, IProduct> >
                {
                    new KeyValuePair <string, IProduct>("cart_list_1", new Good()),
                    new KeyValuePair <string, IProduct>("cart_list_2", new Good())
                };

                var map = new Dictionary <string, IProduct>(listObjects);

                var context = FakeHttpContext.NewFakeHttpContext();

                context.SetupProperty(c => c.Session, FakeHttpContext.FakeSession(map).Object);
                var cart = new Cart(context.Object);
                //Actual
                var actual = cart.All();

                //Assert
                Assert.Equal(expectedList, actual);
            }
Example #4
0
            public void AddProductSingle_WhenDataIsNULL_ExpectedExeption()
            {
                //Arrange
                var map     = new Dictionary <string, IProduct>();
                var context = FakeHttpContext.NewFakeHttpContext();

                context.SetupProperty(e => e.Session, FakeHttpContext.FakeSession(map).Object);

                var cart = new Cart(context.Object);

                //Assert
                Assert.Throws <ArgumentNullException>(() => cart.AddProduct((IProduct)null));
            }
Example #5
0
        public void RemoveWhenProductIsNull()
        {
            //Arrange
            var map = new Dictionary <string, IProduct>(new List <KeyValuePair <string, IProduct> > {
            });

            var context = FakeHttpContext.NewFakeHttpContext();

            context.SetupProperty(e => e.Session, FakeHttpContext.FakeSession(map).Object);
            var cart = new Cart(context.Object);

            //Actual
            cart.Remove(null);
            //Assert
            NAssert.AreEqual(map, map);
        }
Example #6
0
            public void GetAllProductsWhenOnesIsEmpty()
            {
                //Arrange
                var expected = new List <IProduct>();
                var map      = new Dictionary <string, IProduct>();

                var context = FakeHttpContext.NewFakeHttpContext();

                context.SetupProperty(c => c.Session, FakeHttpContext.FakeSession(map).Object);
                var cart = new Cart(context.Object);
                //Actual
                var actual = cart.All();

                //Assert
                Assert.Equal(expected, actual);
            }