예제 #1
0
        public async Task PostFromAnAuthenticatedUserWithValidViewModel_CreatesACountdownFromDateSegmentsWithCorrectTime()
        {
            TestableCountdownController controller = TestableCountdownController.Create();
            const int currentUserAccountId         = 7;

            controller.MockContextService.Setup(x => x.CurrentUserAccountId).Returns(currentUserAccountId);

            var model = new CountdownCreateViewModel {
                Description           = "Test Description",
                SelectedCountdownType = CountdownCreateViewModel.CountdownType.Date,
                EndsOnDay             = 7,
                EndsOnMonth           = 3,
                EndsOnYear            = 2017,
                EndsOnHour            = 13,
                EndsOnMinute          = 5
            };

            ActionResult result = await controller.Create(model);

            Countdown countdown = controller.CountdownRepository.Countdowns.FirstOrDefault();

            Assert.IsNotNull(result);
            Assert.IsNotNull(countdown);
            Assert.AreEqual(model.Description, countdown.Description);
            Assert.AreEqual(currentUserAccountId, countdown.CreatedByAccountId);
            Assert.AreEqual(new DateTime(model.EndsOnYear, model.EndsOnMonth, model.EndsOnDay, (int)model.EndsOnHour, (int)model.EndsOnMinute, 0), countdown.EndsOn);
        }
예제 #2
0
        public async Task PostFromAnAuthenticatedUser_NotifiesConnectedHubClients()
        {
            const int  voteValue   = 1;
            const int  accountId   = 7;
            const long countdownId = 3;
            var        systemTime  = new DateTime(2017, 10, 22, 7, 31, 53);

            TestableCountdownController controller = TestableCountdownController.Create();

            controller.MockContextService.Setup(x => x.CurrentUserAccountId).Returns(accountId);
            controller.MockSystemClock.Setup(x => x.UtcNow).Returns(systemTime);

            controller.CountdownRepository.Countdowns = new List <Countdown> {
                new Countdown {
                    Id = countdownId, CreatedByAccountId = 9
                }
            };

            controller.CountdownRepository.CountdownAggregates = new List <CountdownAggregate> {
                new CountdownAggregate {
                    Id = countdownId, CreatedByAccountId = 9, VoteScore = 3, CurrentUserVote = voteValue
                }
            };

            await controller.Vote(new CountdownVoteViewModel { CountdownId = countdownId, Value = voteValue });

            controller.MockNotificationService
            .Verify(x => x.UpdateClientsAfterVote(It.Is <CountdownAggregate>(c => c.Id == countdownId)),
                    Times.Once());
        }
예제 #3
0
파일: Index.cs 프로젝트: n1ghtmare/Kauntr
        public async Task GetRequest_ReturnsCorrectAModelWithCorrectNumberOfCountdowns()
        {
            TestableCountdownController controller = TestableCountdownController.Create();

            controller.CountdownRepository.CountdownAggregates.Add(new CountdownAggregate());
            controller.CountdownRepository.CountdownAggregates.Add(new CountdownAggregate());
            controller.CountdownRepository.CountdownAggregates.Add(new CountdownAggregate());

            var model = new CountdownListViewModel {
                Page             = 1,
                Token            = 123,
                DisplayOrderType = CountdownDisplayOrderType.Latest,
                Filter           = new CountdownListFilter()
            };

            JsonResult result = await controller.Index(model) as JsonResult;

            Assert.IsNotNull(result);

            CountdownListViewModel resultModel = result.Data as CountdownListViewModel;

            Assert.IsNotNull(resultModel);
            Assert.AreEqual(3, resultModel.Countdowns.Count());
            Assert.AreEqual(3, resultModel.Total);
            Assert.AreEqual(model.Page, resultModel.Page);
            Assert.AreEqual(model.Token, resultModel.Token);
            Assert.AreEqual(model.DisplayOrderType, resultModel.DisplayOrderType);
        }
예제 #4
0
        public async Task PostFromAnAuthenticatedUserWithValidViewModel_CreatesACountdownFromDurationWithCorrectTime(DateTime systemTime, CountdownCreateViewModel.DurationType durationType, int duration, DateTime expectedEndDate)
        {
            TestableCountdownController controller = TestableCountdownController.Create();
            const int currentUserAccountId         = 7;

            controller.MockContextService.Setup(x => x.CurrentUserAccountId).Returns(currentUserAccountId);
            controller.MockSystemClock.Setup(x => x.UtcNow).Returns(systemTime);

            var model = new CountdownCreateViewModel {
                Description           = "Test Description",
                SelectedCountdownType = CountdownCreateViewModel.CountdownType.Duration,
                Duration             = duration,
                SelectedDurationType = durationType
            };

            ActionResult result = await controller.Create(model);

            Countdown countdown = controller.CountdownRepository.Countdowns.FirstOrDefault();

            Assert.IsNotNull(result);
            Assert.IsNotNull(countdown);
            Assert.AreEqual(model.Description, countdown.Description);
            Assert.AreEqual(systemTime, countdown.CreatedOn);
            Assert.AreEqual(expectedEndDate, countdown.EndsOn);
            Assert.AreEqual(currentUserAccountId, countdown.CreatedByAccountId);
        }
예제 #5
0
        public async Task GetWithCountdownIdThatDoesntExist_ReturnsHttpStatusCode404NotFound()
        {
            TestableCountdownController controller = TestableCountdownController.Create();

            HttpStatusCodeResult result = await controller.Details(1) as HttpStatusCodeResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(404, result.StatusCode);
            Assert.AreEqual("Not Found", result.StatusDescription);
        }
예제 #6
0
        public async Task PostFromAnAuthenticatedUserWithInvalidModel_ReturnsHttpStatusCode400BadRequest()
        {
            TestableCountdownController controller = TestableCountdownController.Create();

            controller.ModelState.AddModelError("Nope", "Error Message");

            HttpStatusCodeResult result = await controller.Vote(new CountdownVoteViewModel()) as HttpStatusCodeResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(400, result.StatusCode);
            Assert.AreEqual("Bad Request", result.StatusDescription);
        }
예제 #7
0
        public async Task PostFromAnAuthenticatedUserWithExistingVoteWithDifferentValue_DeletesVoteAndReturnsResultWithNewValue()
        {
            const int  voteValue   = 1;
            const int  accountId   = 7;
            const long countdownId = 3;
            var        systemTime  = new DateTime(2017, 10, 22, 7, 31, 53);

            TestableCountdownController controller = TestableCountdownController.Create();

            controller.MockContextService.Setup(x => x.CurrentUserAccountId).Returns(accountId);
            controller.MockSystemClock.Setup(x => x.UtcNow).Returns(systemTime);

            controller.CountdownRepository.Countdowns = new List <Countdown> {
                new Countdown {
                    Id = countdownId, CreatedByAccountId = 9
                }
            };

            controller.CountdownRepository.CountdownAggregates = new List <CountdownAggregate> {
                new CountdownAggregate {
                    Id = countdownId, CreatedByAccountId = 9, VoteScore = 3, CurrentUserVote = voteValue
                }
            };

            controller.VoteRepository.Votes.Add(new Core.Entities.Vote {
                CountdownId       = countdownId,
                CastedByAccountId = accountId,
                Value             = -1,
                CastedOn          = new DateTime(2017, 10, 11, 7, 31, 53)
            });

            JsonResult result = await controller.Vote(new CountdownVoteViewModel { CountdownId = countdownId, Value = voteValue }) as JsonResult;

            Assert.IsNotNull(result);

            CountdownVoteViewModel model = result.Data as CountdownVoteViewModel;

            Assert.IsNotNull(model);
            Assert.AreEqual(countdownId, model.CountdownId);
            Assert.AreEqual(3, model.VoteScore);
            Assert.AreEqual(voteValue, model.CurrentUserVote);

            Core.Entities.Vote vote = controller.VoteRepository.Votes.FirstOrDefault();
            Assert.IsNotNull(vote);
            Assert.AreEqual(countdownId, vote.CountdownId);
            Assert.AreEqual(voteValue, vote.Value);
            Assert.AreEqual(accountId, vote.CastedByAccountId);
            Assert.AreEqual(systemTime, vote.CastedOn);
        }
예제 #8
0
파일: Index.cs 프로젝트: n1ghtmare/Kauntr
        public async Task GetRequest_ReturnsCountdownListViewModel()
        {
            TestableCountdownController controller = TestableCountdownController.Create();

            var model = new CountdownListViewModel {
                Filter = new CountdownListFilter()
            };
            JsonResult result = await controller.Index(model) as JsonResult;

            Assert.IsNotNull(result);

            CountdownListViewModel resultModel = result.Data as CountdownListViewModel;

            Assert.IsNotNull(resultModel);
        }
예제 #9
0
        public async Task PostFromAnAuthenticatedUserForACountdownCreatedByCurrentUserId_ReturnsHttpStatusCode400BadRequest()
        {
            const int  accountId   = 7;
            const long countdownId = 3;

            TestableCountdownController controller = TestableCountdownController.Create();

            controller.MockContextService.Setup(x => x.CurrentUserAccountId).Returns(accountId);
            controller.CountdownRepository.Countdowns = new List <Countdown> {
                new Countdown {
                    Id = countdownId, CreatedByAccountId = accountId
                }
            };

            HttpStatusCodeResult result = await controller.Vote(new CountdownVoteViewModel { CountdownId = countdownId, Value = 1 }) as HttpStatusCodeResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(400, result.StatusCode);
            Assert.AreEqual("Bad Request", result.StatusDescription);
        }
예제 #10
0
        public async Task PostFromAnAuthenticatedUserWithValidViewModel_ReturnsJsonResultWithCountdownId()
        {
            TestableCountdownController controller = TestableCountdownController.Create();

            controller.MockContextService.Setup(x => x.CurrentUserAccountId).Returns(1);

            var model = new CountdownCreateViewModel {
                Description           = "Test Description",
                SelectedCountdownType = CountdownCreateViewModel.CountdownType.Duration,
                Duration             = 300,
                SelectedDurationType = CountdownCreateViewModel.DurationType.Seconds
            };

            JsonResult result = await controller.Create(model) as JsonResult;

            dynamic data = result?.Data;

            Assert.IsNotNull(result);
            Assert.AreEqual(1, data.Id);
        }
예제 #11
0
        public async Task PostFromAnAuthenticatedUserWithAnExistingVoteWithSameValue_DeletesVoteAndReturnsResultWithANeutralValue()
        {
            const int  voteValue   = 1;
            const int  accountId   = 7;
            const long countdownId = 3;

            TestableCountdownController controller = TestableCountdownController.Create();

            controller.MockContextService.Setup(x => x.CurrentUserAccountId).Returns(accountId);

            controller.VoteRepository.Votes.Add(new Core.Entities.Vote {
                CountdownId       = countdownId,
                CastedByAccountId = accountId,
                Value             = voteValue
            });

            controller.CountdownRepository.Countdowns = new List <Countdown> {
                new Countdown {
                    Id = countdownId, CreatedByAccountId = 9
                }
            };

            controller.CountdownRepository.CountdownAggregates = new List <CountdownAggregate> {
                new CountdownAggregate {
                    Id = countdownId, CreatedByAccountId = 9, VoteScore = 3, CurrentUserVote = null
                }
            };

            JsonResult result = await controller.Vote(new CountdownVoteViewModel { CountdownId = countdownId, Value = voteValue }) as JsonResult;

            Assert.IsNotNull(result);

            CountdownVoteViewModel model = result.Data as CountdownVoteViewModel;

            Assert.IsNotNull(model);
            Assert.AreEqual(countdownId, model.CountdownId);
            Assert.AreEqual(0, model.Value);
            Assert.AreEqual(3, model.VoteScore);
            Assert.IsNull(model.CurrentUserVote);
            Assert.IsEmpty(controller.VoteRepository.Votes);
        }
예제 #12
0
        public async Task PostFromAnAuthenticatedUserWithValuesThatSetAEndsOnDateLessThan5MinutesInFuture_ReturnsHttpStatusCodeResult400BadRequest()
        {
            TestableCountdownController controller = TestableCountdownController.Create();
            var systemTime = new DateTime(2017, 7, 1, 15, 17, 1);

            controller.MockContextService.Setup(x => x.CurrentUserAccountId).Returns(1);
            controller.MockSystemClock.Setup(x => x.UtcNow).Returns(systemTime);

            var model = new CountdownCreateViewModel {
                Description           = "Test Description",
                SelectedCountdownType = CountdownCreateViewModel.CountdownType.Duration,
                Duration             = 71,
                SelectedDurationType = CountdownCreateViewModel.DurationType.Seconds
            };

            HttpStatusCodeResult result = await controller.Create(model) as HttpStatusCodeResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(400, result.StatusCode);
            Assert.AreEqual("Bad Request", result.StatusDescription);
        }
예제 #13
0
        public async Task GetWithCountdownId_ReturnsCountdownAggregate()
        {
            TestableCountdownController controller = TestableCountdownController.Create();
            const long countdownId        = 1;
            var        countdownAggregate = new CountdownAggregate {
                Id                   = countdownId,
                CreatedOn            = DateTime.UtcNow,
                Description          = "test description",
                EndsOn               = DateTime.UtcNow.AddYears(1),
                CreatedByAccountId   = 1,
                CommentsCount        = 37,
                CreatedByDisplayName = "testo",
                CurrentUserVote      = -1,
                VoteScore            = 71
            };

            controller.CountdownRepository.CountdownAggregates.Add(countdownAggregate);

            JsonResult result = await controller.Details(countdownId) as JsonResult;

            Assert.IsNotNull(result);

            CountdownViewModel countdownViewModel = result.Data as CountdownViewModel;

            Assert.IsNotNull(countdownViewModel);
            Assert.AreEqual(countdownAggregate.Id, countdownViewModel.Id);
            Assert.AreEqual(countdownAggregate.CreatedOn, countdownViewModel.CreatedOn);
            Assert.AreEqual(countdownAggregate.Description, countdownViewModel.Description);
            Assert.AreEqual(countdownAggregate.EndsOn, countdownViewModel.EndsOn);
            Assert.AreEqual(countdownAggregate.CreatedByAccountId, countdownViewModel.CreatedByAccountId);
            Assert.AreEqual(countdownAggregate.CommentsCount, countdownViewModel.CommentsCount);
            Assert.AreEqual(countdownAggregate.CreatedByDisplayName, countdownViewModel.CreatedByDisplayName);
            Assert.AreEqual(countdownAggregate.CurrentUserVote, countdownViewModel.CurrentUserVote);
            Assert.AreEqual(countdownAggregate.VoteScore, countdownViewModel.VoteScore);
            Assert.IsNotNull(countdownViewModel.CreatedByGravatarUrl);
        }