Example #1
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 #2
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);
        }