示例#1
0
 protected MrCMSTest()
 {
     _kernel = new MockingKernel();
     Kernel.Load(new TestContextModule());
     Kernel.Bind<IEventContext>().ToMethod(context => _eventContext);
     MrCMSKernel.OverrideKernel(Kernel);
     CurrentRequestData.SiteSettings = new SiteSettings();
 }
示例#2
0
        public void TestInitialEntitiesAreAdded()
        {
            var kernel = new MockingKernel(new EngineModule());

            var systemMock = new Mock<IEntitySystem>();
            systemMock.As<Triggers.IOnEntityAdded>();

            systemMock.Setup(p => p.Filter).Returns(ComponentFilter.Any);
            kernel.Bind<ISystem>().ToConstant(systemMock.Object);

            //var engine = kernel.Get<IEngineFactory>().Create();
        }
示例#3
0
 public DefaultFormRendererTests()
 {
     _formCollection = new FormCollection();
     var mockingKernel = new MockingKernel();
     MrCMSKernel.OverrideKernel(mockingKernel);
     _elementRendererManager = A.Fake<IElementRendererManager>();
     _labelRenderer= A.Fake<ILabelRenderer>();
     _validationMessageRenderer= A.Fake<IValidationMessaageRenderer>();
     _submittedMessageRenderer = A.Fake<ISubmittedMessageRenderer>();
     _siteSettings = new SiteSettings();
     _defaultFormRenderer = new DefaultFormRenderer(_elementRendererManager, _labelRenderer,
                                                    _validationMessageRenderer,_submittedMessageRenderer, _siteSettings);
 }
        public void PrepareForSyncAmazonListingService_UpdateAmazonListing_ShouldSetValues()
        {
            var item = new Currency() { Code = "GBP", Id=1 };
            Session.Transact(session => session.Save(item));

            var mockingKernel = new MockingKernel();
            MrCMSKernel.OverrideKernel(mockingKernel);
            mockingKernel.Bind<ISession>().ToMethod(context => A.Fake<ISession>());
            mockingKernel.Bind<EcommerceSettings>().ToMethod(context => new EcommerceSettings(){CurrencyId = 1});

            var product = new Product()
                {
                    BrandPage = new Brand(){Name = "B"}
                };
            var productVariant = new ProductVariant()
                {
                    Product = product, 
                    SKU = "S1",
                    BasePrice = 1,
                    StockRemaining = 2,
                    Name = "P",
                    ManufacturerPartNumber = "MPN1",
                    Barcode = ""
                };
            var model = new AmazonListing()
            {
                ProductVariant = productVariant,
                StandardProductId = "1P",
                StandardProductIDType = StandardProductIDType.EAN,
                AmazonListingGroup = new AmazonListingGroup()
                {
                    FulfillmentChannel = AmazonFulfillmentChannel.MFN
                }
            };

            A.CallTo(() => _productVariantService.GetProductVariantBySKU(model.ProductVariant.SKU)).Returns(productVariant);

            var results = _prepareForSyncAmazonListingService.UpdateAmazonListing(model);

            results.As<AmazonListing>().Condition.Should().Be(ConditionType.New);
            results.As<AmazonListing>().Currency.Should().Be("GBP");
            results.As<AmazonListing>().Manafacturer.Should().Be("B");
            results.As<AmazonListing>().Brand.Should().Be("B");
            results.As<AmazonListing>().MfrPartNumber.Should().Be("MPN1");
            results.As<AmazonListing>().Price.Should().Be(1);
            results.As<AmazonListing>().Quantity.Should().Be(2);
            results.As<AmazonListing>().Title.Should().Be("P");
            results.As<AmazonListing>().StandardProductIDType.Should().Be(_amazonSellerSettings.BarcodeIsOfType);
            results.As<AmazonListing>().StandardProductId.Should().Be(model.StandardProductId);
            results.As<AmazonListing>().FulfillmentChannel.Should().Be(AmazonFulfillmentChannel.MFN);
        }
        public void AmazonGenerateFeedService_GetProductPrice_ShouldReturnPriceType()
        {
            var mockingKernel = new MockingKernel();
            MrCMSKernel.OverrideKernel(mockingKernel);
            mockingKernel.Bind<ISession>().ToMethod(context => A.Fake<ISession>());

            var model = new AmazonListing()
            {
                SellerSKU = "S1"
            };
            var results = _amazonGenerateFeedService.GetProductPrice(model);

            results.Should().BeOfType<Price>();
        }
        public void BulkShippingUpdateValidationService_ValidateBusinessLogic_CallsAllIoCRegisteredRulesOnAllOrders()
        {
            var mockingKernel = new MockingKernel();
            var validationRules =
                Enumerable.Range(1, 10).Select(i => A.Fake<IBulkShippingUpdateValidationRule>()).ToList();
            validationRules.ForEach(rule => mockingKernel.Bind<IBulkShippingUpdateValidationRule>()
                                                                      .ToMethod(context => rule));
            MrCMSKernel.OverrideKernel(mockingKernel);

            var items = Enumerable.Range(1, 10).Select(i => new BulkShippingUpdateDataTransferObject()).ToList();

            _bulkShippingUpdateValidationService.ValidateBusinessLogic(items);

            validationRules.ForEach(
                rule =>
                EnumerableHelper.ForEach(items, product => A.CallTo(() => rule.GetErrors(product)).MustHaveHappened()));
        }
        public void ImportDocumentsValidationService_ValidateBusinessLogic_CallsAllIoCRegisteredRulesOnAllDocuments()
        {
            var mockingKernel = new MockingKernel();
            List<IDocumentImportValidationRule> documentImportValidationRules =
                Enumerable.Range(1, 10).Select(i => A.Fake<IDocumentImportValidationRule>()).ToList();
            documentImportValidationRules.ForEach(rule => mockingKernel.Bind<IDocumentImportValidationRule>()
                .ToMethod(context => rule));
            MrCMSKernel.OverrideKernel(mockingKernel);

            List<DocumentImportDTO> documents = Enumerable.Range(1, 10).Select(i => new DocumentImportDTO()).ToList();

            _importDocumentsValidationService.ValidateBusinessLogic(documents);

            documentImportValidationRules.ForEach(
                rule =>
                    EnumerableHelper.ForEach(documents,
                        document => A.CallTo(() => rule.GetErrors(document, documents)).MustHaveHappened()));
        }
        public void PrepareForSyncAmazonListingService_UpdateAmazonListing_ShouldReturnAmazonListingType()
        {
            var mockingKernel = new MockingKernel();
            MrCMSKernel.OverrideKernel(mockingKernel);
            mockingKernel.Bind<ISession>().ToMethod(context => A.Fake<ISession>());

            var product = new Product();
            var productVariant = new ProductVariant() { Product = product, SKU = "S1", Barcode = "" };
            var model = new AmazonListing() { ProductVariant = productVariant, AmazonListingGroup = new AmazonListingGroup()
                {
                    FulfillmentChannel = AmazonFulfillmentChannel.MFN
                }};

            A.CallTo(() => _productVariantService.GetProductVariantBySKU(model.ProductVariant.SKU)).Returns(productVariant);

            var results = _prepareForSyncAmazonListingService.UpdateAmazonListing(model);

            results.Should().BeOfType<AmazonListing>();
        }
        public void ImportProductVariantPriceBreakService_ImportVariantPriceBreaks_ShouldCallProductVariantServiceAddPriceBreak()
        {
            var mockingKernel = new MockingKernel();
            var session = A.Fake<ISession>();
            mockingKernel.Bind<ISession>().ToMethod(context => session).InSingletonScope();
            MrCMSKernel.OverrideKernel(mockingKernel);

            var productVariantDTO = new ProductVariantImportDataTransferObject
            {
                PriceBreaks = new Dictionary<int, decimal>() { { 10, 299 } }
            };
            var productVariant = new ProductVariant();

            var priceBreaks = _importProductUrlHistoryService.ImportVariantPriceBreaks(productVariantDTO, productVariant);

            priceBreaks.Should().HaveCount(1);
            var priceBreak = priceBreaks.ToList()[0];
            priceBreak.Price.Should().Be(299);
            priceBreak.Quantity.Should().Be(10);
            priceBreak.ProductVariant.Should().Be(productVariant);
        }
        public void ImportProductsValidationService_ValidateBusinessLogic_CallsAllIoCRegisteredRulesOnAllProducts()
        {
            var mockingKernel = new MockingKernel();
            var productImportValidationRules =
                Enumerable.Range(1, 10).Select(i => A.Fake<IProductImportValidationRule>()).ToList();
            var productVariantImportValidationRule = A.Fake<IProductVariantImportValidationRule>();
            productImportValidationRules.ForEach(rule => mockingKernel.Bind<IProductImportValidationRule>()
                                                                      .ToMethod(context => rule));
            mockingKernel.Bind<IProductVariantImportValidationRule>()
                         .ToMethod(context => productVariantImportValidationRule)
                         .InSingletonScope();
            MrCMSKernel.OverrideKernel(mockingKernel);

            var products = Enumerable.Range(1, 10).Select(i => new ProductImportDataTransferObject()).ToList();

            _importProductsValidationService.ValidateBusinessLogic(products);

            productImportValidationRules.ForEach(
                rule =>
                EnumerableHelper.ForEach(products, product => A.CallTo(() => rule.GetErrors(product)).MustHaveHappened()));
        }
        public void PrepareForSyncAmazonListingService_InitAmazonListingFromProductVariant_ShouldCallSave()
        {
            var item = new Currency() { Code = "GBP", Id = 1 };
            Session.Transact(session => session.Save(item));

            var mockingKernel = new MockingKernel();
            MrCMSKernel.OverrideKernel(mockingKernel);
            mockingKernel.Bind<ISession>().ToMethod(context => A.Fake<ISession>());
            mockingKernel.Bind<EcommerceSettings>().ToMethod(context => new EcommerceSettings() { CurrencyId = 1 });

            var product = new Product()
            {
                BrandPage = new Brand() { Name = "B" }
            };
            var productVariant = new ProductVariant()
            {
                Product = product,
                SKU = "S1",
                BasePrice = 1,
                StockRemaining = 2,
                Name = "P",
                ManufacturerPartNumber = "MPN1",
                Barcode = ""
            };
            var amazonListingGroup = new AmazonListingGroup()
            {
                Id = 1,
                FulfillmentChannel = AmazonFulfillmentChannel.MFN
            };
            var model = new AmazonListing()
            {
                ProductVariant = productVariant,
                StandardProductId = "1P",
                StandardProductIDType = StandardProductIDType.EAN,
                AmazonListingGroup = amazonListingGroup
            };

            A.CallTo(() => _amazonListingGroupService.Get(amazonListingGroup.Id)).Returns(amazonListingGroup);

            A.CallTo(() => _productVariantService.GetProductVariantBySKU(model.ProductVariant.SKU)).Returns(productVariant);

            var results = _prepareForSyncAmazonListingService.InitAmazonListingFromProductVariant(model, model.ProductVariant.SKU, amazonListingGroup.Id);

            A.CallTo(() =>  _amazonListingGroupService.Save(amazonListingGroup)).MustHaveHappened();
        }
        public void PrepareForSyncAmazonListingService_InitAmazonListingFromProductVariant_ShouldReturnAmazonListingType()
        {
            var mockingKernel = new MockingKernel();
            MrCMSKernel.OverrideKernel(mockingKernel);
            mockingKernel.Bind<ISession>().ToMethod(context => A.Fake<ISession>());

            var model = new AmazonListing();

            var results = _prepareForSyncAmazonListingService.InitAmazonListingFromProductVariant(model,"S1",1);

            results.Should().BeOfType<AmazonListing>();
        }
        public void AmazonGenerateFeedService_GetProductPrice_ShouldSetValues()
        {
            var mockingKernel = new MockingKernel();
            MrCMSKernel.OverrideKernel(mockingKernel);
            mockingKernel.Bind<ISession>().ToMethod(context => A.Fake<ISession>());

            var listing = new AmazonListing()
            {
                SellerSKU = "S1",
                Price = 1
            };
            var results = _amazonGenerateFeedService.GetProductPrice(listing);

            results.As<Price>().StandardPrice.Value.Should().Be(listing.Price);
            results.As<Price>().StandardPrice.Currency.Should().Be(BaseCurrencyCodeWithDefault.USD);
            results.As<Price>().SKU.Should().Be(listing.SellerSKU);
        }