public void BuildProductListProductWithOneVariantsImageTest()
        {
            // Arrange
            var rules       = MockRepository.GenerateMock <ISiteRules>();
            var productList = new ProductItemPagedList
            {
                ItemCount = 1,
                Items     = new ProductItemList
                {
                    new ProductItem
                    {
                        ImageKey        = Guid.NewGuid(),
                        VariantImageKey = Guid.NewGuid()
                    }
                }
            };

            var dictionary = MockRepository.GenerateMock <IApplicationDictionary>();

            var stormContext = MockRepository.GenerateMock <IStormContext>();

            stormContext.Stub(x => x.Configuration).Return(new StormConfigurationSection());
            stormContext.Stub(x => x.ShowPricesIncVat).Return(false);
            StormContext.SetInstance(stormContext);

            // Act
            var productBuilder = new ProductListBuilder(dictionary, rules);
            var result         = productBuilder.BuildProductList(productList);

            // Assert
            Assert.AreEqual(1, result.Items[0].Files.Count);
            Assert.AreEqual(1, result.Items[0].Variants[0].Files.Count);
        }
Example #2
0
        public void SaveCookieTest1()
        {
            // Arrange
            var application = CreateDefaultApplication();
            var repository  = MockRepository.GenerateMock <IRepository>();

            repository.Stub(x => x.GetApplication()).IgnoreArguments().Return(application);

            var httpContextWrapper = CreateEmptyHttpContextMock();

            httpContextWrapper.RequestCookies.Add(new HttpCookie("StormSession")
            {
                Value = null
            });
            httpContextWrapper.RequestCookies.Add(new HttpCookie("StormPersisted")
            {
                Value = null
            });
            var ctx = new StormContext(repository, httpContextWrapper);

            StormContext.SetInstance(ctx);

            // Act
            StormContext.LoadCookie();
            StormContext.BasketId   = 1;
            StormContext.CustomerId = 123456;
            StormContext.LoginName  = "*****@*****.**";
            StormContext.SaveCookie();

            // Assert
            Assert.AreEqual("[email protected]&AccountId=!null!&CustomerId=123456&CompanyId=!null!&DivisionId=!null!&BasketId=1&CurrencyId=1&CultureCode=sv-SE&SalesAreaId=1&ShowPricesIncVat=!null!&IsPrivate=True&ReferId=!null!&RememberMe=True", httpContextWrapper.ResponseCookies["StormPersisted"].Value);
        }
Example #3
0
        public void BuildProductModelTest02()
        {
            // Arrange
            var rules   = MockRepository.GenerateMock <ISiteRules>();
            var product = new Product
            {
                Id           = 1,
                Name         = "MockProduct",
                Manufacturer = new ProductManufacturer {
                    Id = 1, Name = "MockManufacturer"
                },
                CategoryId   = null,
                CategoryName = "MockCategory"
            };

            var stormContext = MockRepository.GenerateMock <IStormContext>();

            stormContext.Stub(x => x.Configuration).Return(new StormConfigurationSection());
            stormContext.Stub(x => x.ShowPricesIncVat).Return(false);
            StormContext.SetInstance(stormContext);

            var dictionary = MockRepository.GenerateMock <IApplicationDictionary>();

            // Act
            var productBuilder = new ProductBuilder(dictionary, rules);
            var result         = productBuilder.BuildProductModel(product);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("MockProduct", result.Name);
            Assert.AreEqual("MockManufacturer", result.Manufacturer.Name);
            Assert.AreEqual("MockCategory", result.Category.Name);
        }
Example #4
0
        public void CreateNoHttpStormContextTest()
        {
            // Arrange
            var application = new Application
            {
                Currencies = new Currencies {
                    Default = new Currency {
                        Id = 2
                    }
                },
                Cultures = new Cultures {
                    Default = new Culture {
                        Code = "da-DK"
                    }
                },
                SalesAreas = new SalesAreas {
                    Default = new SalesArea {
                        Id = 1
                    }
                },
            };

            var httpContextWrapper = new NoHttpContext(application);
            var ctx = new StormContext(new Repository(), httpContextWrapper);

            StormContext.SetInstance(ctx);

            // Act
            StormContext.ShowPricesIncVat = true;

            // Assert
            Assert.AreEqual(true, StormContext.ShowPricesIncVat);
        }
Example #5
0
        public void ProcessRequestWithoutBasketTest1()
        {
            // Arrange
            var application = CreateDefaultApplication();

            var repository = MockRepository.GenerateMock <IRepository>();

            repository.Stub(x => x.GetApplication()).IgnoreArguments().Return(application);

            var httpContextWrapper = CreateEmptyHttpContextMock();
            var ctx = new StormContext(repository, httpContextWrapper);

            StormContext.SetInstance(ctx);

            var handler = new PaynovaCallbackHandler(repository);
            var request = new HttpContext(
                new HttpRequest("", application.Url, ""),
                new HttpResponse(new StringWriter()));

            // Act
            handler.ProcessRequest(request);

            // Assert
            repository.AssertWasNotCalled(x => x.GetBasket(1), o => o.IgnoreArguments());
        }
Example #6
0
        public void ProcessValidRequestWithFailedResponseTest1()
        {
            // Arrange
            var application = CreateDefaultApplication();
            var customer    = CreateDefaultCustomer();
            var basket      = new Basket {
                Id = 1,
            };

            var repository = MockRepository.GenerateMock <IRepository>();

            repository.Stub(x => x.GetApplication()).IgnoreArguments().Return(application);
            repository.Stub(x => x.GetCustomerByEmail("*****@*****.**")).IgnoreArguments().Return(customer);
            repository.Stub(x => x.GetBasket(1)).IgnoreArguments().Return(basket);
            repository.Stub(x => x.PaymentCallback2(null)).IgnoreArguments().Return(new PaymentResponse {
                Status = "FAIL", StatusDescription = "This was NOT OK."
            });

            var httpContextWrapper = CreateEmptyHttpContextMock();
            var ctx = new StormContext(repository, httpContextWrapper);

            StormContext.SetInstance(ctx);
            StormContext.BasketId = 1;

            var handler = new PaynovaCallbackHandler(repository);
            var request = new HttpContext(
                new HttpRequest("", application.Url, ""),
                new HttpResponse(new StringWriter()));

            // Act
            handler.ProcessRequest(request);

            // Assert
            repository.AssertWasCalled(x => x.PaymentCancel(null), o => o.IgnoreArguments());
        }
Example #7
0
        public void MapPriceTest07()
        {
            // Arrange
            var product = new ProductItem
            {
                VatRate     = 1.25m,
                PriceListId = null,
                Price       = 100
            };

            var stormContext = MockRepository.GenerateMock <IStormContext>();

            stormContext.Stub(x => x.Configuration).Return(new StormConfigurationSection());
            stormContext.Stub(x => x.ShowPricesIncVat).Return(false);
            StormContext.SetInstance(stormContext);

            // Act
            var result = MockBuilderBase.MapPrice(product);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1.25m, result.VatRate);
            Assert.AreEqual(0, result.PricelistId);
            Assert.AreEqual(100, result.Display);
            Assert.AreEqual(100, result.Catalog);
            Assert.AreEqual(100, result.Recommended);
        }
        public void InitializeTest()
        {
            var stormUtilsRepo = new Mock <Enferno.Web.StormUtils.InternalRepository.IRepository>();

            var application = new Application
            {
                Currencies = new Currencies {
                    Default = new Currency {
                        Id = 2
                    }
                },
                Cultures = new Cultures {
                    Default = new Culture {
                        Code = "sv-SE"
                    }
                },
                SalesAreas = new SalesAreas {
                    Default = new SalesArea {
                        Id = 1
                    }
                },
            };

            var httpContextWrapper = new NoHttpContext(application);
            var ctx = new StormContext(stormUtilsRepo.Object, httpContextWrapper);

            StormContext.SetInstance(ctx);
        }
        public void BuildProductList03Test()
        {
            // Arrange
            var rules       = MockRepository.GenerateMock <ISiteRules>();
            var productList = new ProductItemPagedList
            {
                ItemCount = 1,
                Items     = new ProductItemList
                {
                    new ProductItem
                    {
                        Manufacturer = new ProductManufacturer {
                            Id = 1, Name = "MockManufacturer"
                        }
                    }
                }
            };

            var dictionary = MockRepository.GenerateMock <IApplicationDictionary>();

            var stormContext = MockRepository.GenerateMock <IStormContext>();

            stormContext.Stub(x => x.Configuration).Return(new StormConfigurationSection());
            stormContext.Stub(x => x.ShowPricesIncVat).Return(false);
            StormContext.SetInstance(stormContext);

            // Act
            var productBuilder = new ProductListBuilder(dictionary, rules);
            var result         = productBuilder.BuildProductList(productList);

            // Assert
            Assert.AreEqual(0, result.Filters.Count);
            Assert.AreEqual(1, result.ItemCount);
            Assert.AreEqual("MockManufacturer", result.Items[0].Manufacturer.Name);
        }
Example #10
0
        public void LoadCookieInvalidCookieWithRefreshTest1()
        {
            // Arrange
            var application = CreateDefaultApplication();
            var repository  = MockRepository.GenerateMock <IRepository>();

            repository.Stub(x => x.GetApplication()).IgnoreArguments().Return(application);

            var httpContextWrapper = CreateEmptyHttpContextMock();

            httpContextWrapper.RequestCookies.Add(new HttpCookie("StormSession")
            {
                Value = null
            });
            httpContextWrapper.RequestCookies.Add(new HttpCookie("StormPersisted")
            {
                Value = "LoginName=!null!&AccountId=!null!&CustomerId=!null!&CompanyId=!null!&DivisionId=!null!&BasketId=!null!&CurrencyId=5&CultureCode=da-DK&SalesAreaId=3&ShowPricesIncVat=!null!&IsPrivate=True&ReferId=!null!&ReferUrl=!null!&RememberMe=True"
            });
            var ctx = new StormContext(repository, httpContextWrapper);

            StormContext.SetInstance(ctx);

            // Act
            StormContext.LoadCookie();

            // Assert
            Assert.AreEqual("sv-SE", StormContext.CultureCode);
            Assert.AreEqual(1, StormContext.CurrencyId);
            Assert.AreEqual(1, StormContext.SalesAreaId);
        }
Example #11
0
        public void CreateUserWhenUserExistsTest1()
        {
            // Arrange
            var application = CreateDefaultApplication();
            var customer    = CreateDefaultCustomer();

            customer.Account.Authorizations.Add(new IdValue {
                Id = 1, Value = "NormalUser"
            });
            var repository = MockRepository.GenerateMock <IRepository>();

            repository.Stub(x => x.GetApplication()).IgnoreArguments().Return(application);
            repository.Stub(x => x.GetCustomerByLoginName("*****@*****.**")).IgnoreArguments().Return(customer);

            var httpContextWrapper = CreateEmptyHttpContextMock();
            var ctx = new StormContext(repository, httpContextWrapper);

            StormContext.SetInstance(ctx);

            var provider = new StormMembershipProvider(repository);

            InitializeProvider(provider);

            // Act
            MembershipCreateStatus status;

            provider.CreateUser("*****@*****.**", "abc", "*****@*****.**", "question", "answer", true, null, out status);

            // Assert
            Assert.AreEqual(MembershipCreateStatus.DuplicateUserName, status);
        }
Example #12
0
        public void ValidateUserTest1()
        {
            // Arrange
            var application = CreateDefaultApplication();
            var customer    = CreateDefaultCustomer();

            customer.Account.Authorizations.Add(new IdValue {
                Id = 1, Value = "NormalUser"
            });
            var repository = MockRepository.GenerateMock <IRepository>();

            repository.Stub(x => x.GetApplication()).IgnoreArguments().Return(application);
            repository.Stub(x => x.GetCustomerByEmail("*****@*****.**")).IgnoreArguments().Return(customer);
            repository.Stub(x => x.Login("*****@*****.**", "abc")).IgnoreArguments().Return(customer);

            var httpContextWrapper = CreateEmptyHttpContextMock();
            var ctx = new StormContext(repository, httpContextWrapper);

            StormContext.SetInstance(ctx);

            var provider = new StormMembershipProvider(repository);

            // Act
            var success = provider.ValidateUser("*****@*****.**", "abc");

            // Assert
            Assert.IsTrue(success);
        }
Example #13
0
        public void GetUserNameByEmail1()
        {
            // Arrange
            var application = CreateDefaultApplication();
            var customer    = CreateDefaultCustomer();

            customer.Account.Authorizations.Add(new IdValue {
                Id = 1, Value = "NormalUser"
            });
            var repository = MockRepository.GenerateMock <IRepository>();

            repository.Stub(x => x.GetApplication()).IgnoreArguments().Return(application);
            repository.Stub(x => x.GetCustomerByEmail("*****@*****.**")).IgnoreArguments().Return(customer);

            var httpContextWrapper = CreateEmptyHttpContextMock();
            var ctx = new StormContext(repository, httpContextWrapper);

            StormContext.SetInstance(ctx);

            var provider = new StormMembershipProvider(repository);

            InitializeProvider(provider);

            // Act
            var name = provider.GetUserNameByEmail("*****@*****.**");

            // Assert
            Assert.AreEqual("*****@*****.**", name);
        }
Example #14
0
        public void LoginUserTest1()
        {
            // Arrange
            var application = CreateDefaultApplication();
            var customer    = CreateDefaultCustomer();

            var repository = MockRepository.GenerateMock <IRepository>();

            repository.Stub(x => x.GetApplication()).IgnoreArguments().Return(application);
            repository.Stub(x => x.GetCustomerByLoginName("*****@*****.**")).IgnoreArguments().Return(customer);

            var httpContextWrapper = CreateEmptyHttpContextMock();

            var ctx = new StormContext(repository, httpContextWrapper);

            StormContext.SetInstance(ctx);

            // Act
            StormContext.LoginUser("*****@*****.**");

            // Assert
            Assert.AreEqual("*****@*****.**", StormContext.LoginName);
            Assert.AreEqual(1, StormContext.CustomerId);
            Assert.AreEqual(2, StormContext.AccountId);
        }
Example #15
0
        public void MapProductWithFilesTest()
        {
            // Arrange
            var product = new Product
            {
                Files = new ProductFileList
                {
                    new ProductFile {
                        Description = "Desc1", Name = "Name1", Id = 11, Key = Guid.NewGuid(), Path = "file1.jpg", Type = (int)FileType.Jpg
                    },
                    new ProductFile {
                        Description = "Desc2", Name = "Name2", Id = 46, Key = Guid.NewGuid(), Path = "file2.mp4", Type = (int)ExternalFileType.Mp4
                    },
                    new ProductFile {
                        Description = "Desc3", Name = "Name3", Id = 47, Key = Guid.NewGuid(), Path = "file3.eps", Type = (int)ExternalFileType.Eps
                    }
                },
            };

            var stormContext = MockRepository.GenerateMock <IStormContext>();

            stormContext.Stub(x => x.Configuration).Return(new StormConfigurationSection());
            StormContext.SetInstance(stormContext);
            // Act

            var model = Mapper.Map <Product, ProductModel>(product);

            // Assert
            Assert.IsNotNull(model);
            Assert.AreEqual(3, model.Files.Count);
            Assert.IsTrue(model.Files[0].Url.EndsWith("jpg"), "jpg");
            Assert.IsTrue(model.Files[1].Url.EndsWith("mp4"), "mp4");
            Assert.IsTrue(model.Files[2].Url.EndsWith("eps"), "eps");
        }
Example #16
0
        public void LogoutUserTest2()
        {
            // Arrange
            var application = CreateDefaultApplication();
            var customer    = CreateDefaultCustomer();
            var basket      = new Basket {
                Id = 1,
            };

            var repository = MockRepository.GenerateMock <IRepository>();

            repository.Stub(x => x.GetApplication()).IgnoreArguments().Return(application);
            repository.Stub(x => x.GetCustomerByLoginName("*****@*****.**")).IgnoreArguments().Return(customer);
            repository.Stub(x => x.GetBasket(1)).IgnoreArguments().Return(basket);

            var httpContextWrapper = CreateEmptyHttpContextMock();
            var ctx = new StormContext(repository, httpContextWrapper);

            StormContext.SetInstance(ctx);
            StormContext.BasketId = 1;

            // Act
            StormContext.LoginUser("*****@*****.**");
            Assert.IsNotNull(StormContext.LoginName);
            StormContext.LogoutUser();

            // Assert
            repository.AssertWasCalled(x => x.UpdateBuyer(basket.Id.GetValueOrDefault(1), customer), o => o.IgnoreArguments());
            Assert.IsNull(StormContext.LoginName);
            Assert.IsNull(StormContext.AccountId);
            Assert.IsNull(StormContext.CompanyId);
            Assert.IsNull(StormContext.CustomerId);
        }
Example #17
0
        public void LoadAndSaveWithBasketIdCookieTest1()
        {
            // Arrange
            var application = CreateDefaultApplication();
            var repository  = MockRepository.GenerateMock <IRepository>();

            repository.Stub(x => x.GetApplication()).IgnoreArguments().Return(application);

            var httpContextWrapper = CreateRealHttpContextMock();

            httpContextWrapper.RequestCookies.Add(new HttpCookie("StormSession")
            {
                Value = null
            });
            httpContextWrapper.RequestCookies.Add(new HttpCookie("StormPersisted")
            {
                Value = null
            });
            var ctx = new StormContext(repository, httpContextWrapper);

            StormContext.SetInstance(ctx);

            // Act
            StormContext.LoadCookie();
            StormContext.BasketId = 4711;
            StormContext.SaveCookie();
            StormContext.LoadCookie();

            // Assert
            Assert.AreEqual(4711, StormContext.BasketId);
        }
Example #18
0
        public void LoadCookieEmptyCookieTest1()
        {
            // Arrange
            var application = CreateDefaultApplication();
            var repository  = MockRepository.GenerateMock <IRepository>();

            repository.Stub(x => x.GetApplication()).IgnoreArguments().Return(application);

            var httpContextWrapper = CreateEmptyHttpContextMock();

            httpContextWrapper.RequestCookies.Add(new HttpCookie("StormSession")
            {
                Value = null
            });
            httpContextWrapper.RequestCookies.Add(new HttpCookie("StormPersisted")
            {
                Value = null
            });
            var ctx = new StormContext(repository, httpContextWrapper);

            StormContext.SetInstance(ctx);

            // Act
            StormContext.LoadCookie();

            // Assert
            Assert.AreEqual("sv-SE", StormContext.CultureCode);
            Assert.AreEqual(1, StormContext.CurrencyId);
            Assert.AreEqual(1, StormContext.SalesAreaId);
        }
        public void BuildProductListProductWithNoAdditionalImageWhenVariantSpecificTest()
        {
            // Arrange
            var rules       = MockRepository.GenerateMock <ISiteRules>();
            var productList = new ProductItemPagedList
            {
                ItemCount = 1,
                Items     = new ProductItemList
                {
                    new ProductItem {
                        ImageKey = Guid.NewGuid(), VariantImageKey = Guid.NewGuid(), AdditionalImageKeySeed = "58:11111111-e238-476d-9886-9f2193539d2a"
                    },
                    new ProductItem {
                        ImageKey = Guid.NewGuid(), VariantImageKey = Guid.NewGuid(), AdditionalImageKeySeed = "58:22222222-e238-476d-9886-9f2193539d2a"
                    },
                }
            };

            var dictionary = MockRepository.GenerateMock <IApplicationDictionary>();

            var stormContext = MockRepository.GenerateMock <IStormContext>();

            stormContext.Stub(x => x.Configuration).Return(new StormConfigurationSection());
            stormContext.Stub(x => x.ShowPricesIncVat).Return(false);
            StormContext.SetInstance(stormContext);

            // Act
            var productBuilder = new ProductListBuilder(dictionary, rules);
            var result         = productBuilder.BuildProductList(productList);

            // Assert
            Assert.AreEqual(1, result.Items[0].Files.Count);
            Assert.AreEqual(2, result.Items[0].Variants[0].Files.Count);
            Assert.AreEqual(2, result.Items[0].Variants[1].Files.Count);
        }
Example #20
0
        public void GetRolesForUserTest1()
        {
            // Arrange
            var application = CreateDefaultApplication();
            var customer    = CreateDefaultCustomer();

            customer.Account.Authorizations.Add(new IdValue {
                Id = 1, Value = "NormalUser"
            });
            var repository = MockRepository.GenerateMock <IRepository>();

            repository.Stub(x => x.GetApplication()).IgnoreArguments().Return(application);
            repository.Stub(x => x.GetCustomerByEmail("*****@*****.**")).IgnoreArguments().Return(customer);

            var httpContextWrapper = CreateEmptyHttpContextMock();
            var ctx = new StormContext(repository, httpContextWrapper);

            StormContext.SetInstance(ctx);

            var provider = new StormRoleProvider(repository);

            // Act
            var roles = provider.GetRolesForUser("*****@*****.**");

            // Assert
            Assert.AreEqual(1, roles.Length);
            Assert.AreEqual("NormalUser", roles[0]);
        }
Example #21
0
        public static ApplicationIdentityContext Create()
        {
            var database = new StormContext();

            var users = database.context.GetCollection <IdentityUser>("users");
            var roles = database.context.GetCollection <IdentityRole>("roles");

            return(new ApplicationIdentityContext(users, roles));
        }
        public void Init()
        {
            IoC.RegisterType <ISiteRules, TestSiteRules>();

            var stormContext = MockRepository.GenerateMock <IStormContext>();

            stormContext.Stub(x => x.Configuration).Return(new StormConfigurationSection());
            stormContext.Stub(x => x.ShowPricesIncVat).Return(true);
            stormContext.Stub(x => x.CultureCode).Return("sv");
            StormContext.SetInstance(stormContext);
        }
Example #23
0
        /// <summary>
        /// Create an instance of the specified component type
        /// </summary>
        /// <param name="type">The component type</param>
        /// <param name="sc">Storm context</param>
        /// <param name="config">Storm configuration</param>
        /// <returns></returns>
        public static T CreateComponent <T>(StormContext sc, Dictionary <string, object> config) where T : Component
        {
            // Create component instance
            T comp = (T)Activator.CreateInstance(typeof(T));

            // Set context and configuration singleton
            comp.Context       = sc;
            comp.Configuration = config;
            comp.Channel       = new TestChannel();

            return(comp);
        }
Example #24
0
        public void GetLoginNameTest()
        {
            // Arrange
            var ctx = MockRepository.GenerateMock <IStormContext>();

            ctx.Stub(x => x.LoginName).Return("*****@*****.**");

            StormContext.SetInstance(ctx);

            // Assert
            Assert.AreEqual("*****@*****.**", StormContext.LoginName);
        }
Example #25
0
        public static List <WeeklyReportViewModel> GetWeeklyReportsUKSA(this List <User> users,
                                                                        DateTime startDate, DateTime endDate,
                                                                        StormContext db)
        {
            // Declare a list of weekly reports and populate it according to the users and date parameters
            var weeklyReportVMList = new List <WeeklyReportViewModel>();

            foreach (var user in users)
            {
                var weeklyReportVM = new WeeklyReportViewModel
                {
                    Name     = user.Name,
                    Location = user.Location.StormLocationName
                };

                foreach (var rfq in db.RFQs.Where(r => r.LoginID == user.LoginID && r.RFQDate > startDate && r.RFQDate < endDate))
                {
                    if (rfq.Status == "CAN")
                    {
                        if (rfq.AccountManager.EndsWith("UK"))
                        {
                            weeklyReportVM.UKRFQs++;
                            rfq.Content.ForEach(c => weeklyReportVM.UKLineItems += Convert.ToInt64(c.Qty));
                        }
                        else if (rfq.AccountManager.EndsWith("SA"))
                        {
                            weeklyReportVM.SARFQs++;
                            rfq.Content.ForEach(c => weeklyReportVM.SALineItems += Convert.ToInt64(c.Qty));
                        }
                    }
                    else
                    {
                        if (rfq.AccountManager.EndsWith("UK"))
                        {
                            weeklyReportVM.UKCancelledRFQs++;
                            rfq.Content.ForEach(c => weeklyReportVM.UKCancelledLineItems += Convert.ToInt64(c.Qty));
                        }
                        else if (rfq.AccountManager.EndsWith("SA"))
                        {
                            weeklyReportVM.SACancelledRFQs++;
                            rfq.Content.ForEach(c => weeklyReportVM.SACancelledLineItems += Convert.ToInt64(c.Qty));
                        }
                    }
                }
                //Add the newly populated WeeklyReportVM to the list declared at the beginning
                weeklyReportVMList.Add(weeklyReportVM);
            }

            // Return the list
            return(weeklyReportVMList);
        }
Example #26
0
        public void EncryptCookieTrueTest()
        {
            //Arrange
            var ctx = MockRepository.GenerateMock <IStormContext>();
            var cfg = MockRepository.GenerateMock <IStormConfigurationSection>();

            cfg.Stub(x => x.EncryptCookie).Return(true);
            ctx.Stub(x => x.Configuration).Return(cfg);

            StormContext.SetInstance(ctx);

            // Assert
            Assert.IsTrue(StormContext.Configuration.EncryptCookie);
        }
Example #27
0
        public void GetCookieTest()
        {
            // Arrange
            var ctx = MockRepository.GenerateMock <IStormContext>();

            ctx.Stub(x => x.GetCookie("jalle")).IgnoreArguments().Return(new HttpCookie("jalle"));

            StormContext.SetInstance(ctx);

            // Act
            var cookie = StormContext.GetCookie("jalle");

            // Assert
            Assert.AreEqual("jalle", cookie.Name);
        }
        public void CanGetProductFromId()
        {
            // Arrange
            var stormContext = MockRepository.GenerateMock <IStormContext>();

            stormContext.Stub(x => x.Configuration).Return(new StormConfigurationSection());
            stormContext.Stub(x => x.ShowPricesIncVat).Return(false);
            stormContext.Stub(x => x.CultureCode).Return("sv");
            StormContext.SetInstance(stormContext);

            var productsRepository = MockRepository.GenerateMock <IProductRepository>();

            productsRepository.Stub(x => x.ListParametricInfo()).IgnoreArguments()
            .Return(
                new ParametricInfoList
            {
                new ParametricInfo {
                    Id = 111, Type = ParametricType.ListValue, ValueType = ParametricValueType.Integer
                }
            }
                );

            productsRepository.Stub(x => x.ListParametricValues()).IgnoreArguments()
            .Return(
                new ParametricValueList
            {
                new ParametricValue {
                    Id = 37, Name = "Valuee", Description = "Desc", Code = "Coode", SortOrder = 1, Type = ParametricType.ListValue.ToString()
                }
            }
                );

            var repository = MockRepository.GenerateMock <IRepository>();

            repository.Stub(x => x.Products).Return(productsRepository);

            IoC.Container.RegisterInstance(typeof(IRepository), "IRepository", repository, new SingletonLifetimeManager());
            ApplicationDictionary.Instance.Refresh();

            var productViewModel = productManager.GetProduct(product.Id);

            Assert.IsNotNull(productViewModel);
            Assert.AreEqual(product.PriceListId, productViewModel.PriceListId);
            Assert.AreEqual(product.Price, productViewModel.DisplayPrice);
        }
        public void BuildFiltersWhenListHasMixedWithCountEqualsItemCountTest()
        {
            // Arrange
            var rules = MockRepository.GenerateMock <ISiteRules>();

            var filterList = new FilterList
            {
                new Filter {
                    Name = "flgf", Items = new FilterItemList
                    {
                        new FilterItem {
                            Code = "Flag0", Count = 0, Id = "3", Value = "0"
                        },
                        new FilterItem {
                            Code = "Flag1", Count = 1, Id = "3", Value = "1"
                        },
                        new FilterItem {
                            Code = "Flag2", Count = 2, Id = "3", Value = "2"
                        }
                    }
                },
            };

            var stormContext = MockRepository.GenerateMock <IStormContext>();

            stormContext.Stub(x => x.Configuration).Return(new StormConfigurationSection());
            stormContext.Stub(x => x.ShowPricesIncVat).Return(true);
            stormContext.Stub(x => x.CultureCode).Return("sv");
            StormContext.SetInstance(stormContext);

            var applicationDictionary = MockRepository.GenerateMock <IApplicationDictionary>();

            // Act
            var filterBuilder = new FilterBuilder(applicationDictionary, rules);

            filterBuilder.ItemCount = 2;
            var result = filterBuilder.BuildFilters(filterList).ToList();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(1, result[0].Values.Count);
        }
        [Test] public static void TestExample()
        {
            // Initialize configuration
            Dictionary <string, object> config = GetConfig();

            // Initialize context
            StormContext sc = GetContext();

            // Create, and run a spout
            EmitSentence es = UnitTest.CreateComponent <EmitSentence>(sc, config);

            es.Next();
            List <TestOutput> res = es.GetOutput();

            // Verify results and metadata
            Assert.True(res.Count > 0);
            Assert.True(res[0].Stream == "default");
            Assert.True(res[0].ComponentId == "componentid1");

            // Create, and run 1st Bolt
            sc.ComponentId = "componentid2";
            SplitSentence ss = UnitTest.CreateComponent <SplitSentence>(sc, config);

            foreach (var output in res)
            {
                ss.Execute(new StormTuple(((SpoutOutput)output).Id, "EmitSentence", "TaskId", output.Stream, output.Tuple));
            }
            res = ss.GetOutput();

            // Verify results and metadata
            Assert.True(res.Count > 0);
            Assert.True(res[0].Stream == "default");

            // Create, and run 2nd Bolt
            sc.ComponentId = "componentid3";
            CountWords cw = UnitTest.CreateComponent <CountWords>(sc, config);

            foreach (var output in res)
            {
                cw.Execute(new StormTuple("id", "SplitSentence", "TaskId", output.Stream, output.Tuple));
            }
        }