コード例 #1
0
        public void GetCurrencyCodeWillReturnDefaultCurrencyCodeWhenProfileIsNotUserProfile()
        {
            // Fixture setup
            var profile = new Mock<ProfileBase>().Object;

            var httpContextStub = new Mock<HttpContextBase>();
            httpContextStub.SetupGet(ctx => ctx.Profile).Returns(profile);

            var sut = new DefaultCurrencyProfileService(httpContextStub.Object);
            // Exercise system
            var result = sut.GetCurrencyCode();
            // Verify outcome
            Assert.Equal<string>("DKK", result);
            // Teardown
        }
コード例 #2
0
        public void GetCurrencyCodeWillReturnDefaultCurrencyCodeWhenUserProfileCurrencyIsNull()
        {
            // Fixture setup
            var userProfileStub = new Mock<UserProfile>();
            userProfileStub.SetupGet(up => up.Currency).Returns((string)null);

            var httpContextStub = new Mock<HttpContextBase>();
            httpContextStub.SetupGet(ctx => ctx.Profile).Returns(userProfileStub.Object);

            var sut = new DefaultCurrencyProfileService(httpContextStub.Object);
            // Exercise system
            var result = sut.GetCurrencyCode();
            // Verify outcome
            Assert.Equal<string>("DKK", result);
            // Teardown
        }
コード例 #3
0
        public void GetCurrencyCodeWillReturnProfileFromContextWhenThatProfileIsUserProfile()
        {
            // Fixture setup
            var fixture = new ControllerFixture();
            var expectedCurrencyCode = fixture.CreateAnonymous("CurrencyCode");

            var userProfileStub = new Mock<UserProfile>();
            userProfileStub.SetupGet(up => up.Currency).Returns(expectedCurrencyCode);

            var httpContextStub = new Mock<HttpContextBase>();
            httpContextStub.SetupGet(ctx => ctx.Profile).Returns(userProfileStub.Object);

            var sut = new DefaultCurrencyProfileService(httpContextStub.Object);
            // Exercise system
            var result = sut.GetCurrencyCode();
            // Verify outcome
            Assert.Equal<string>(expectedCurrencyCode, result);
            // Teardown
        }
コード例 #4
0
        public void UpdateCurrencyCodeWhenProfileIsNotUserProfileWillThrow()
        {
            // Fixture setup
            var fixture = new Fixture();
            var profile = new Mock<ProfileBase>().Object;

            var httpContextStub = new Mock<HttpContextBase>();
            httpContextStub.SetupGet(ctx => ctx.Profile).Returns(profile);

            var sut = new DefaultCurrencyProfileService(httpContextStub.Object);
            // Exercise system and verify outcome
            Assert.Throws<InvalidOperationException>(() =>
                fixture.Do((string currencyCode) =>
                    sut.UpdateCurrencyCode(currencyCode)));
            // Teardown
        }
コード例 #5
0
        public void UpdateCurrencyCodeWillSaveProfile()
        {
            // Fixture setup
            var fixture = new Fixture();
            var currencyCode = fixture.CreateAnonymous("CurrencyCode");

            var userProfileMock = new Mock<UserProfile>();
            userProfileMock.SetupSet(up => up.Currency = currencyCode).Verifiable();
            userProfileMock.Setup(up => up.Save()).Verifiable();

            var httpContextStub = new Mock<HttpContextBase>();
            httpContextStub.SetupGet(ctx => ctx.Profile).Returns(userProfileMock.Object);

            var sut = new DefaultCurrencyProfileService(httpContextStub.Object);
            // Exercise system
            sut.UpdateCurrencyCode(currencyCode);
            // Verify outcome
            userProfileMock.Verify();
            // Teardown
        }