Beispiel #1
0
        public async Task GetRequestWithAnIdAndAnAuthenticatedUser_ReturnsAModelIndicatingThatItWasCreatedByTheCurrentUser() {
            const int countdownId = 123;
            const int currentAccountId = 1337;

            var countdownController = TestableCountdownController.Create();
            var fakeResult = new CountdownAggregate {
                IsCreatedByCurrentUser = true
            };

            countdownController.MockContextService
                               .Setup(x => x.GetCurrentAccountAsync())
                               .Returns(Task.FromResult(new Account {Id = currentAccountId}));

            countdownController.MockCountdownRepository
                               .Setup(x => x.GetAggregateByIdAsync(countdownId, currentAccountId))
                               .Returns(Task.FromResult(fakeResult));

            var result = await countdownController.Details(countdownId) as ViewResult;

            Assert.IsNotNull(result);
            var model = result.Model as CountdownViewModel;

            Assert.IsNotNull(model);
            Assert.IsTrue(model.IsCreatedByCurrentUser);
        }
Beispiel #2
0
        public async Task GetRequestWithAnId_ReturnsCorrectlyMappedDetailsViewModel() {
            const int countdownId = 123;

            var countdownController = TestableCountdownController.Create();
            var fakeResult = new CountdownAggregate {
                Id = countdownId,
                Description = "Test Counter Description",
                EndsOn = new DateTime(2013, 01, 01, 12, 35, 10).ToUniversalTime(),
                CreatedOn = DateTime.UtcNow,
                VoteScore = 1,
                IsCreatedByCurrentUser = false,
                CreatedByName = "DisplayName",
                CreatedByEmail = "*****@*****.**"
            };

            countdownController.MockCountdownRepository
                               .Setup(x => x.GetAggregateByIdAsync(countdownId, null))
                               .Returns(Task.FromResult(fakeResult));

            var result = await countdownController.Details(countdownId) as ViewResult;

            Assert.IsNotNull(result);
            var model = result.Model as CountdownViewModel;

            Assert.IsNotNull(model);
            Assert.AreEqual(fakeResult.Id, model.Id);
            Assert.AreEqual(fakeResult.Description, model.Description);
            Assert.AreEqual(fakeResult.EndsOn, model.EndsOn);
            Assert.AreEqual(fakeResult.CreatedOn, model.CreatedOn);
            Assert.AreEqual(fakeResult.IsCreatedByCurrentUser, model.IsCreatedByCurrentUser);
            Assert.AreEqual(fakeResult.CreatedByName, model.CreatedByName);
            Assert.AreEqual(fakeResult.CreatedByEmail, model.CreatedByEmail);
            Assert.AreEqual(1, model.VoteScore);
        }