コード例 #1
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
        }
コード例 #2
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
        }