Exemple #1
0
        public async Task AddNewActor_WhenAllParametersAreValid()
        {
            var dabataseName = nameof(AddNewActor_WhenAllParametersAreValid);

            var options = ActorTestUtils.GetOptions(dabataseName);

            var mappingProviderMock = new Mock <IMappingProvider>();

            string actorName = "Michael Jordan";

            using (var arrangeContext = new MovieManagementContext(options))
            {
                var sut = new ActorService(arrangeContext, mappingProviderMock.Object);


                await sut.CreateActorAsync(actorName);

                arrangeContext.SaveChanges();
            }

            using (var actAndAssertContext = new MovieManagementContext(options))
            {
                Assert.IsTrue(actAndAssertContext.Actors.Count() == 1);
                Assert.IsTrue(actAndAssertContext.Actors.Any(m => m.Name == actorName));
            }
        }
        public async Task Succeed_ReturnActor()
        {
            var options = TestUtils.GetOptions(nameof(Succeed_ReturnActor));

            using (var assertContext = new MoviesCatalogContext(options))
            {
                var sut = new ActorService(assertContext);

                var actor = await sut.CreateActorAsync("Brad", "Pit", null, "Very good actor");

                Assert.AreEqual(actor.FirstName, "Brad");
                Assert.AreEqual(actor.LastName, "Pit");
                Assert.AreEqual(actor.Biography, "Very good actor");
            }
        }
Exemple #3
0
        public async Task Throw_WhenActor_DoesExists()
        {
            var dabataseName = nameof(Throw_WhenActor_DoesExists);

            var options = ActorTestUtils.GetOptions(dabataseName);

            ActorTestUtils.FillContextWithActors(options);

            var mappingProviderMock = new Mock <IMappingProvider>();

            using (var actAndAssertContext = new MovieManagementContext(options))
            {
                var sut = new ActorService(actAndAssertContext, mappingProviderMock.Object);

                string actorName = "Julia Roberts";

                await Assert.ThrowsExceptionAsync <EntityAlreadyExistsException>(
                    async() => await sut.CreateActorAsync(actorName));
            }
        }
Exemple #4
0
        public async Task ReturnCorrectViewModel()
        {
            var dabataseName = nameof(ReturnCorrectViewModel);

            var options = ActorTestUtils.GetOptions(dabataseName);

            var mappingProviderMock = new Mock <IMappingProvider>();

            mappingProviderMock.Setup(x => x.MapTo <ActorViewModel>(It.IsAny <Actor>())).Returns(new ActorViewModel());

            using (var actAndAssertContext = new MovieManagementContext(options))
            {
                var sut = new ActorService(actAndAssertContext, mappingProviderMock.Object);

                string actorName = "Michael Jordan";

                var result = await sut.CreateActorAsync(actorName);

                Assert.IsInstanceOfType(result, typeof(ActorViewModel));
            }
        }