Ejemplo n.º 1
0
        public void TryUpdateModelIsCalled_WhenItemIsFound()
        {
            // Arrange
            var viewMock = new Mock <ITournamentView>();

            viewMock.Setup(v => v.ModelState).Returns(new ModelStateDictionary());
            int tournamentId    = 1;
            var tournamentName  = "Tournament 1";
            var tournamentDate  = new DateTime(2017, 02, 01);
            var tournamentPrize = 1;

            var tournamentServiceMock = new Mock <ITournamentService>();

            tournamentServiceMock.Setup(c => c.GetTournamentById(tournamentId)).Returns(new List <Tournament> {
                new Tournament()
                {
                    Id = tournamentId, Name = tournamentName, Date = tournamentDate, Prize = tournamentPrize
                }
            });

            TournamentPresenter tournamentPresenter = new TournamentPresenter(viewMock.Object, tournamentServiceMock.Object);

            // Act
            viewMock.Raise(v => v.OnUpdateItem += null, new IdEventArgs(tournamentId));

            // Assert
            viewMock.Verify(v => v.TryUpdateModel(It.IsAny <Tournament>()), Times.Once());
        }
Ejemplo n.º 2
0
        public void UpdateCategoryIsNotCalled_WhenItemIsFoundAndIsInInvalidState()
        {
            // Arrange
            var viewMock   = new Mock <ITournamentView>();
            var modelState = new ModelStateDictionary();

            modelState.AddModelError("test key", "test message");
            viewMock.Setup(v => v.ModelState).Returns(modelState);

            int tournamentId    = 1;
            var tournamentName  = "Tournament 1";
            var tournamentDate  = new DateTime(2017, 02, 01);
            var tournamentPrize = 1;
            var tournament      = new Tournament()
            {
                Id = tournamentId, Name = tournamentName, Date = tournamentDate, Prize = tournamentPrize
            };
            var tournamentServiceMock = new Mock <ITournamentService>();

            tournamentServiceMock.Setup(c => c.GetTournamentById(tournamentId)).Returns(new List <Tournament> {
                new Tournament()
                {
                    Id = tournamentId, Name = tournamentName, Date = tournamentDate, Prize = tournamentPrize
                }
            });

            TournamentPresenter tournamentPresenter = new TournamentPresenter(viewMock.Object, tournamentServiceMock.Object);

            // Act
            viewMock.Raise(v => v.OnUpdateItem += null, new IdEventArgs(tournamentId));

            // Assert
            tournamentServiceMock.Verify(c => c.UpdateTournament(tournament), Times.Never());
        }
Ejemplo n.º 3
0
        public void TryUpdateModelIsNotCalled_WhenItemIsNotFound()
        {
            // Arrange
            var viewMock = new Mock <ITournamentView>();

            viewMock.Setup(v => v.ModelState).Returns(new ModelStateDictionary());
            string errorKey              = string.Empty;
            int    tournamentId          = 1;
            var    tournamentServiceMock = new Mock <ITournamentService>();

            tournamentServiceMock.Setup(c => c.GetTournamentById(tournamentId)).Returns <Tournament>(null);

            TournamentPresenter tournamentPresenter = new TournamentPresenter
                                                          (viewMock.Object, tournamentServiceMock.Object);

            // Act
            viewMock.Raise(v => v.OnUpdateItem += null, new IdEventArgs(tournamentId));

            // Assert
            viewMock.Verify(v => v.TryUpdateModel(It.IsAny <Tournament>()), Times.Never());
        }
Ejemplo n.º 4
0
        public void CallGetAllTournamentsSortedById_WhenOnGetDataEventIsRaised()
        {
            //Arrange
            var viewMock = new Mock <ITournamentView>();

            viewMock.Setup(v => v.Model).Returns(new TournamentViewModel());

            var tournaments           = GetTournaments();
            var tournamentServiceMock = new Mock <ITournamentService>();

            tournamentServiceMock.Setup(c => c.GetAllTournamentsSortedById())
            .Returns(tournaments);

            TournamentPresenter tournamentPresenter = new TournamentPresenter(viewMock.Object, tournamentServiceMock.Object);

            // Act
            viewMock.Raise(v => v.OnGetData += null, EventArgs.Empty);

            // Assert
            CollectionAssert.AreEquivalent(tournaments, viewMock.Object.Model.Tournaments); // TODO CHECK ORDER
        }
Ejemplo n.º 5
0
        public void AddModelError_WhenItemIsNotFound()
        {
            // Arrange
            var viewMock = new Mock <ITournamentView>();

            viewMock.Setup(v => v.ModelState).Returns(new ModelStateDictionary());
            string errorKey              = string.Empty;
            int    tournamentId          = 1;
            string expectedError         = String.Format("Item with id {0} was not found", tournamentId);
            var    tournamentServiceMock = new Mock <ITournamentService>();

            tournamentServiceMock.Setup(t => t.GetTournamentById(tournamentId)).Returns <Tournament>(null);

            TournamentPresenter tournamentPresenter = new TournamentPresenter
                                                          (viewMock.Object, tournamentServiceMock.Object);

            // Act
            viewMock.Raise(v => v.OnUpdateItem += null, new IdEventArgs(tournamentId));
            var actualResult = viewMock.Object.ModelState[errorKey].Errors[0].ErrorMessage;

            // Assert
            Assert.AreEqual(1, viewMock.Object.ModelState[errorKey].Errors.Count);
            StringAssert.AreEqualIgnoringCase(expectedError, actualResult);
        }