コード例 #1
0
        public void ShouldCreateAnInstaceOfIDishesAsyncService_WhenParametersAreCorrect()
        {
            var asyncRepository   = new Mock <IDishesAsyncRepository>();
            var unitOfWorkFactory = new Mock <IDisposableUnitOfWorkFactory>();
            var usersRepository   = new Mock <IUsersAsyncRepository>();
            var dishFactory       = new Mock <IInitializedDishFactory>();
            var videoItemFactory  = new Mock <IInitializedVideoItemFactory>();
            var photoItemFactory  = new Mock <IInitializedPhotoItemFactory>();

            var actualInstace = new DishesAsyncService(asyncRepository.Object, usersRepository.Object, dishFactory.Object, videoItemFactory.Object, photoItemFactory.Object, unitOfWorkFactory.Object);

            Assert.That(actualInstace, Is.Not.Null.And.InstanceOf <IDishesAsyncService>());
        }
コード例 #2
0
        public void ShouldAssignFieldDishesAsyncRepositoryWithCorrectType_WhenParametersAreCorrect()
        {
            var asyncRepository   = new Mock <IDishesAsyncRepository>();
            var unitOfWorkFactory = new Mock <IDisposableUnitOfWorkFactory>();
            var usersRepository   = new Mock <IUsersAsyncRepository>();
            var dishFactory       = new Mock <IInitializedDishFactory>();
            var videoItemFactory  = new Mock <IInitializedVideoItemFactory>();
            var photoItemFactory  = new Mock <IInitializedPhotoItemFactory>();

            var actualInstace = new DishesAsyncService(asyncRepository.Object, usersRepository.Object, dishFactory.Object, videoItemFactory.Object, photoItemFactory.Object, unitOfWorkFactory.Object);

            var bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance;
            var dishesAsyncRepositoryField = typeof(DishesAsyncService).GetField("dishesAsyncRepository", bindingFlags);

            Assert.That(dishesAsyncRepositoryField.FieldType, Is.EqualTo(typeof(IDishesAsyncRepository)));
        }
コード例 #3
0
        public void ShouldInvokeAsyncRepository_GetTopCountDishesByRatingMethodOnceWithCorrectParameter(int dishesCount)
        {
            var asyncRepository = new Mock <IDishesAsyncRepository>();

            asyncRepository.Setup(repo => repo.GetTopCountDishesByRating(It.IsAny <int>())).Returns(Task.Run <ICollection <NamePhotoRatingDishViewDTO> >(() => new List <NamePhotoRatingDishViewDTO>()));

            var unitOfWorkFactory = new Mock <IDisposableUnitOfWorkFactory>();
            var usersRepository   = new Mock <IUsersAsyncRepository>();
            var dishFactory       = new Mock <IInitializedDishFactory>();
            var videoItemFactory  = new Mock <IInitializedVideoItemFactory>();
            var photoItemFactory  = new Mock <IInitializedPhotoItemFactory>();

            var dishesAsyncService = new DishesAsyncService(asyncRepository.Object, usersRepository.Object, dishFactory.Object, videoItemFactory.Object, photoItemFactory.Object, unitOfWorkFactory.Object);

            dishesAsyncService.GetTopCountDishesByRating(dishesCount, false);

            asyncRepository.Verify(repo => repo.GetTopCountDishesByRating(dishesCount), Times.Once);
        }
コード例 #4
0
        public void ShouldThrowArgumentExceptionWithCorrectMessage_WhenDishesCountParameterIsNegative(int dishesCount)
        {
            var asyncRepository = new Mock <IDishesAsyncRepository>();

            asyncRepository.Setup(repo => repo.GetTopCountDishesByRating(It.IsAny <int>())).Returns(Task.Run <ICollection <NamePhotoRatingDishViewDTO> >(() => new List <NamePhotoRatingDishViewDTO>()));

            var unitOfWorkFactory = new Mock <IDisposableUnitOfWorkFactory>();
            var usersRepository   = new Mock <IUsersAsyncRepository>();
            var dishFactory       = new Mock <IInitializedDishFactory>();
            var videoItemFactory  = new Mock <IInitializedVideoItemFactory>();
            var photoItemFactory  = new Mock <IInitializedPhotoItemFactory>();

            var dishesAsyncService = new DishesAsyncService(asyncRepository.Object, usersRepository.Object, dishFactory.Object, videoItemFactory.Object, photoItemFactory.Object, unitOfWorkFactory.Object);

            Assert.That(
                () => dishesAsyncService.GetTopCountDishesByRating(dishesCount, false),
                Throws.InstanceOf <ArgumentException>().With.Message.Contains("dishesCount parameter must be greater than or equal to 0."));
        }
コード例 #5
0
        public void ShouldReturnCorrectType_WhenParameteresAreCorrect()
        {
            var asyncRepository = new Mock <IDishesAsyncRepository>();

            asyncRepository.Setup(repo => repo.GetTopCountDishesByRating(It.IsAny <int>())).Returns(Task.Run <ICollection <NamePhotoRatingDishViewDTO> >(() => new List <NamePhotoRatingDishViewDTO>()));

            var unitOfWorkFactory = new Mock <IDisposableUnitOfWorkFactory>();
            var usersRepository   = new Mock <IUsersAsyncRepository>();
            var dishFactory       = new Mock <IInitializedDishFactory>();
            var videoItemFactory  = new Mock <IInitializedVideoItemFactory>();
            var photoItemFactory  = new Mock <IInitializedPhotoItemFactory>();

            var dishesAsyncService = new DishesAsyncService(asyncRepository.Object, usersRepository.Object, dishFactory.Object, videoItemFactory.Object, photoItemFactory.Object, unitOfWorkFactory.Object);

            var dishesCount  = 3;
            var actualResult = dishesAsyncService.GetTopCountDishesByRating(dishesCount, false);

            Assert.That(actualResult, Is.InstanceOf <IEnumerable <NamePhotoRatingDishViewDTO> >());
        }