示例#1
0
        public void CanBuy_EverythingOk_Buy()
        {
            equipmentService.Setup(x => x.GetAllowedProductsForEntity(It.IsAny <EntityTypeEnum>())).Returns(new List <ProductTypeEnum>()
            {
                ProductTypeEnum.Bread
            });
            var country = new CountryDummyCreator()
                          .CreateNewRegion()
                          .CreateNewRegion()
                          .Create();

            var citizen = new CitizenDummyCreator()
                          .SetCountry(country)
                          .Create();
            var citizenTrader = new CitizenTrader(citizen.Entity, equipmentService.Object);


            var mockTrader = new Mock <ITrader>();

            mockTrader.SetupGet(x => x.TraderType).Returns(TraderTypeEnum.Shop);
            mockTrader.SetupGet(x => x.RegionID).Returns(citizen.RegionID);

            var offer = offerCreator
                        .SetProduct(ProductTypeEnum.Bread)
                        .Create();

            var result = citizenTrader.CanBuy(offer, mockTrader.Object);

            Assert.IsTrue(result.isSuccess);
        }
示例#2
0
        public void CanBuy_ProductsNotForCitizen_CannotBuy()
        {
            ProductTypeEnum[] forCitizen = { ProductTypeEnum.Bread, ProductTypeEnum.Weapon, ProductTypeEnum.MovingTicket, ProductTypeEnum.Tea, ProductTypeEnum.House };

            var citizen       = new CitizenDummyCreator().Create();
            var citizenTrader = new CitizenTrader(citizen.Entity, equipmentService.Object);


            foreach (var productType in Enums.ToArray <ProductTypeEnum>())
            {
                if (forCitizen.Contains(productType))
                {
                    continue;
                }

                var mockTrader = new Mock <ITrader>();
                mockTrader.SetupGet(x => x.TraderType).Returns(TraderTypeEnum.Shop);

                var offer = offerCreator
                            .SetProduct(productType)
                            .Create();

                var result = citizenTrader.CanBuy(offer, mockTrader.Object);

                Assert.IsTrue(result.Is(TraderErrors.YouCannotBuyThat));
            }
        }
示例#3
0
        public void CanBuy_OfferNotInRegion_CannotBuy()
        {
            equipmentService.Setup(x => x.GetAllowedProductsForEntity(It.IsAny <EntityTypeEnum>())).Returns(new List <ProductTypeEnum>()
            {
                ProductTypeEnum.Bread
            });
            var country = new CountryDummyCreator()
                          .CreateNewRegion()
                          .CreateNewRegion()
                          .Create();

            var citizen = new CitizenDummyCreator()
                          .SetCountry(country)
                          .Create();
            var citizenTrader = new CitizenTrader(citizen.Entity, equipmentService.Object);


            var mockTrader = new Mock <ITrader>();

            mockTrader.SetupGet(x => x.TraderType).Returns(TraderTypeEnum.Shop);

            var offer = offerCreator
                        .SetProduct(ProductTypeEnum.Bread)
                        .SetRegion(country.Regions.ElementAt(1))
                        .Create();

            var result = citizenTrader.CanBuy(offer, mockTrader.Object);

            Assert.IsTrue(result.Is(TraderErrors.NotSelledInYourRegion));
        }
示例#4
0
        public void CanBuy_SellerNotShop_CannotBuy()
        {
            equipmentService.Setup(x => x.GetAllowedProductsForEntity(It.IsAny <EntityTypeEnum>())).Returns(new List <ProductTypeEnum>()
            {
                ProductTypeEnum.Bread
            });
            var citizen       = new CitizenDummyCreator().Create();
            var citizenTrader = new CitizenTrader(citizen.Entity, equipmentService.Object);


            var mockTrader = new Mock <ITrader>();

            mockTrader.SetupGet(x => x.TraderType).Returns(TraderTypeEnum.Hotel);

            var offer = offerCreator
                        .SetProduct(ProductTypeEnum.Bread)
                        .Create();

            var result = citizenTrader.CanBuy(offer, mockTrader.Object);

            Assert.IsTrue(result.Is(TraderErrors.YouCannotBuyThat));
        }