コード例 #1
0
        public void AddMovieCommand_WhenGenreIsAnimationMightNotContainAnActor_ShouldSucceed()
        {
            //Arrange
            var director = EntitiesFake.GenerateCastFake(id: Guid.NewGuid());
            var casts    = new List <Cast>()
            {
                director
            };

            _fixture.GetCastSetup(casts);

            var castIds = new List <Guid>()
            {
                director.Id
            };
            var addMovieCommand = CommandsFake.GenerateAddMovieCommandFake(
                title: "Arrival",
                genre: Genre.Animation,
                castIds: castIds);

            _fixture.HasNotificationsSetup(false);
            _fixture.CommitSetup();

            //Act
            var result = _commandHandler.Handle(addMovieCommand, CancellationToken.None);

            //Assert
            var errorMessage = $"The movie must have at least one actor!";

            _fixture.Mocker.GetMock <IDomainNotificationHandler <DomainNotification> >().Verify(x => x.Handle(
                                                                                                    It.Is <DomainNotification>(x => x.Value.Equals(errorMessage)),
                                                                                                    It.IsAny <CancellationToken>()), Times.Never);

            _fixture.Mocker.GetMock <IMovieRepository>()
            .Verify(x => x.GetCast(It.IsAny <Expression <Func <Cast, bool> > >()), Times.Once);

            _fixture.Mocker.GetMock <IMovieRepository>()
            .Verify(x => x.Add(It.Is <Movie>(movie =>
                                             movie.Title == addMovieCommand.Title &&
                                             movie.Genre == addMovieCommand.Genre &&
                                             addMovieCommand.CastIds.All(x => movie.CastOfMovies.Select(x => x.CastId).Contains(x)))),
                    Times.Once);

            _fixture.Mocker.GetMock <IUnitOfWork>().Verify(x => x.Commit(), Times.Once);

            Assert.True(result.Result);
        }
コード例 #2
0
        public void AddMovieCommand_ShouldSucceed()
        {
            //Arrange
            var actor1   = EntitiesFake.GenerateCastFake(id: Guid.NewGuid(), type: CastType.Actor);
            var actor2   = EntitiesFake.GenerateCastFake(id: Guid.NewGuid(), type: CastType.Actor);
            var director = EntitiesFake.GenerateCastFake(id: Guid.NewGuid());
            var casts    = new List <Cast>()
            {
                actor1, actor2, director
            };

            _fixture.GetCastSetup(casts);

            var castIds = new List <Guid>()
            {
                actor1.Id, actor2.Id, director.Id
            };
            var addMovieCommand = CommandsFake.GenerateAddMovieCommandFake(
                title: "Arrival",
                genre: Genre.SciFi,
                castIds: castIds);

            _fixture.CommitSetup();
            _fixture.HasNotificationsSetup(false);

            //Act
            var result = _commandHandler.Handle(addMovieCommand, CancellationToken.None);

            //Assert
            _fixture.Mocker.GetMock <IMovieRepository>()
            .Verify(x => x.GetCast(It.IsAny <Expression <Func <Cast, bool> > >()), Times.Once);

            _fixture.Mocker.GetMock <IMovieRepository>()
            .Verify(x => x.Add(It.Is <Movie>(movie =>
                                             movie.Title == addMovieCommand.Title &&
                                             movie.Genre == addMovieCommand.Genre &&
                                             addMovieCommand.CastIds.All(x => movie.CastOfMovies.Select(x => x.CastId).Contains(x)))),
                    Times.Once);

            _fixture.Mocker.GetMock <INotificationHandler <DomainNotification> >()
            .Verify(x => x.Handle(It.IsAny <DomainNotification>(), It.IsAny <CancellationToken>()),
                    Times.Never);

            _fixture.Mocker.GetMock <IUnitOfWork>().Verify(x => x.Commit(), Times.Once);

            Assert.True(result.Result);
        }
コード例 #3
0
        public void AddMovieCommand_WhenCastDoesNotExists_ShouldReturnErrorMessage()
        {
            //Arrange
            var actor1   = EntitiesFake.GenerateCastFake(id: Guid.NewGuid(), type: CastType.Actor);
            var actor2   = EntitiesFake.GenerateCastFake(id: Guid.NewGuid(), type: CastType.Actor);
            var director = EntitiesFake.GenerateCastFake(id: Guid.NewGuid());
            var casts    = new List <Cast>()
            {
                actor1, director
            };

            _fixture.GetCastSetup(casts);

            var castIds = new List <Guid>()
            {
                actor1.Id, actor2.Id, director.Id
            };
            var addMovieCommand = CommandsFake.GenerateAddMovieCommandFake(
                title: "Arrival",
                genre: Genre.SciFi,
                castIds: castIds);

            _fixture.HasNotificationsSetup(true);

            //Act
            var result = _commandHandler.Handle(addMovieCommand, CancellationToken.None);

            //Assert
            var errorMessage = $"Cast not found. Id: {actor2.Id}";

            _fixture.Mocker.GetMock <IDomainNotificationHandler <DomainNotification> >().Verify(x => x.Handle(
                                                                                                    It.Is <DomainNotification>(x => x.Value.Equals(errorMessage)),
                                                                                                    It.IsAny <CancellationToken>()), Times.Once);

            _fixture.Mocker.GetMock <IMovieRepository>()
            .Verify(x => x.GetCast(It.IsAny <Expression <Func <Cast, bool> > >()), Times.Once);

            _fixture.Mocker.GetMock <IMovieRepository>().Verify(x => x.Add(It.IsAny <Movie>()), Times.Never);

            _fixture.Mocker.GetMock <IUnitOfWork>().Verify(x => x.Commit(), Times.Never);

            Assert.False(result.Result);
        }
コード例 #4
0
        public void AddMovieCommand_WhenGenreIsNotAnimationShouldContainAtLeastOneActor_ShouldReturnErrorMessage(Genre genre)
        {
            //Arrange
            var director = EntitiesFake.GenerateCastFake(id: Guid.NewGuid());
            var casts    = new List <Cast>()
            {
                director
            };

            _fixture.GetCastSetup(casts);

            var castIds = new List <Guid>()
            {
                director.Id
            };
            var addMovieCommand = CommandsFake.GenerateAddMovieCommandFake(
                title: "Arrival",
                genre: Genre.SciFi,
                castIds: castIds);

            _fixture.HasNotificationsSetup(true);

            //Act
            var result = _commandHandler.Handle(addMovieCommand, CancellationToken.None);

            //Assert

            var errorMessage = $"The movie must have at least one actor!";

            _fixture.Mocker.GetMock <IDomainNotificationHandler <DomainNotification> >().Verify(x => x.Handle(
                                                                                                    It.Is <DomainNotification>(x => x.Value.Equals(errorMessage)),
                                                                                                    It.IsAny <CancellationToken>()), Times.Once);

            _fixture.Mocker.GetMock <IMovieRepository>()
            .Verify(x => x.GetCast(It.IsAny <Expression <Func <Cast, bool> > >()), Times.Once);

            _fixture.Mocker.GetMock <IMovieRepository>().Verify(x => x.Add(It.IsAny <Movie>()), Times.Never);

            _fixture.Mocker.GetMock <IUnitOfWork>().Verify(x => x.Commit(), Times.Never);

            Assert.False(result.Result);
        }