public void DeletePost()
        {
            AutoMapperDataConfig.RegisterMappings();
            PublisherService publisherService = new PublisherService(new PostRepository(), new TagRepository());

            int maxId = publisherService.GetAllPosts().Max(x => x.Id);

            var postDto = new PostDto()
            {
                Id = maxId
            };

            publisherService.Delete(postDto);

            var postDeleted = publisherService.GetById(maxId);

            Assert.IsNull(postDeleted);
        }
Beispiel #2
0
        /// <summary>
        /// 专为图书修改页提供的添加图书
        /// </summary>
        /// <param name="title"></param>
        /// <param name="isbn"></param>
        /// <param name="Publisherid"></param>
        /// <param name="WordsCount"></param>
        /// <param name="AurhorDescription"></param>
        /// <param name="UnitPrice"></param>
        /// <param name="author"></param>
        /// <param name="TOC"></param>
        /// <param name="PublishDate"></param>
        /// <param name="ContentDescription"></param>
        /// <param name="editorComment"></param>
        public static void AddBook(string title, string isbn, int Publisherid, int WordsCount, string AurhorDescription, decimal UnitPrice, string author, string TOC, DateTime PublishDate, string ContentDescription, string editorComment)
        {
            Book book = new Book();

            book.Category           = CategoryService.GetCategoryById(1);
            book.Title              = title;
            book.ISBN               = isbn;
            book.UnitPrice          = UnitPrice;
            book.Author             = author;
            book.TOC                = TOC;
            book.Publisher          = PublisherService.GetPublisherById(Publisherid);
            book.WordsCount         = WordsCount;
            book.AurhorDescription  = AurhorDescription;
            book.PublishDate        = PublishDate;
            book.ContentDescription = ContentDescription;
            book.EditorComment      = editorComment;
            book.Clicks             = 0;
            BookService.AddBook(book);
        }
        public UserModule(IServiceProvider serviceProvider, Settings.Deserialized.Settings settings, Rules rules)
        {
            _databaseService  = serviceProvider.GetService <DatabaseService>();
            _userService      = serviceProvider.GetService <UserService>();
            _publisherService = serviceProvider.GetService <PublisherService>();
            _updateService    = serviceProvider.GetService <UpdateService>();
            _currencyService  = serviceProvider.GetService <CurrencyService>();
            _rules            = rules;
            _settings         = settings;

            var commandHandlingService = serviceProvider.GetService <CommandHandlingService>();

            Task.Run(async() =>
            {
                var commands = await commandHandlingService.GetCommandList("UserModule", false, true, false);
                //TODO Work out a decent way to remove duplicates?
                _commandList = commands.MessageSplitToSize();
            });
        }
Beispiel #4
0
        public async Task AddShouldAddPublisher()
        {
            var optionsBuilder = new DbContextOptionsBuilder <BookTubeContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var dbContext = new BookTubeContext(optionsBuilder.Options);
            var service   = new PublisherService(dbContext);

            var publisher = new Publisher
            {
                Id       = 1,
                Name     = "Siela",
                Contacts = "Sofia, Bulgaria"
            };

            await service.AddPublisher(publisher.Name, publisher.Contacts);

            var publisherFromDb = dbContext.Publishers.Select(x => x.Name).First();

            Assert.Equal(publisherFromDb, publisher.Name);
        }
        public async Task FindBookTraderAsyncShouldReturnNullIfBookDoesntExists()
        {
            //Arrange
            var db = await this.GetDatabase();

            await this.SeedDb(db);

            var authorService    = new AuthorService(db);
            var publisherService = new PublisherService(db);

            var bookService = new BookService(db, authorService, publisherService);

            //Act
            var result = await bookService.FindBookTraderAsync(4);

            //Assert
            result
            .Should()
            .BeNull();
        }
        public async Task ExistsAsyncShouldReturnFalseIfBookByGivenParametersDoesntExists()
        {
            //Arrange
            var db = await this.GetDatabase();

            await this.SeedDb(db);

            var authorService    = new AuthorService(db);
            var publisherService = new PublisherService(db);

            var bookService = new BookService(db, authorService, publisherService);

            //Act
            var result = await bookService.ExistsAsync("saafa", BookId);

            //Assert
            result
            .Should()
            .BeFalse();
        }
Beispiel #7
0
        //添加图书信息
        public static void AddBook(string Title, string Author, string AurhorDescription, string ContentDescription, string ISBN,
                                   string EditorComment, string TOC, int publisherid, int WordsCount, decimal UnitPrice, DateTime PublishDate)
        {
            Books book = new Books();

            book.Catagorys          = CatagoryService.GetCatagoryById(1);
            book.Title              = Title;
            book.Author             = Author;
            book.ISBN               = ISBN;
            book.UnitPrice          = UnitPrice;
            book.TOC                = TOC;
            book.Publisher          = PublisherService.GetPublishersById(publisherid);
            book.WordsCount         = WordsCount;
            book.AurhorDescription  = AurhorDescription;
            book.PublishDate        = PublishDate;
            book.ContentDescription = ContentDescription;
            book.EditorComment      = EditorComment;
            book.Clicks             = 0;
            BookService.AddBook(book);
        }
        public async Task FindTitleShouldReturnTitleIfBookExists()
        {
            //Arrange
            var db = await this.GetDatabase();

            await this.SeedDb(db);

            var authorService    = new AuthorService(db);
            var publisherService = new PublisherService(db);

            var bookService = new BookService(db, authorService, publisherService);

            //Act
            var result = bookService.FindTitle(BookId);

            //Assert
            result
            .Should()
            .BeEquivalentTo("Third Book");
        }
        public async Task GetCoverPictureShouldReturnNullIfDoesntExists()
        {
            //Arrange
            var db = await this.GetDatabase();

            await this.SeedDb(db);

            var authorService    = new AuthorService(db);
            var publisherService = new PublisherService(db);

            var bookService = new BookService(db, authorService, publisherService);

            //Act
            var result = await bookService.GetCoverPicture(2);

            //Assert
            result
            .Should()
            .BeNull();
        }
        public void ShouldNotRestoreVideoDeletedNormally_WhenPublisherRestored()
        {
            var publisherService = new PublisherService();
            var publisher        = publisherService.CreateAndRetrievePublisher(new CreatePublisherDto("", "", -1, "", testLibrary.LibraryId));

            var videoToCreate = GetNewVideoDetails(publisher);
            var videoId       = repository.CreateVideo(videoToCreate);

            repository.DeleteVideo(videoId).ConfigureAwait(false);

            publisherService.DeletePublisher(publisher).ConfigureAwait(false);
            publisherService.RestorePublisher(publisher).ConfigureAwait(false);
            var videoRetrieved = repository.GetVideo(videoId).Result;

            CollectionAssert.AreEquivalent(new List <Video>()
            {
                videoRetrieved
            }, repository.GetDeletedVideos(GetFirstPage()).Result.Results);
            CollectionAssert.AreEquivalent(new List <Video>(), repository.GetVideos(GetFirstPage()).Result.Results);
        }
Beispiel #11
0
        public void TestDeletePublisher()
        {
            var mockSet = new Mock <DbSet <Publisher> >();

            var mockContext = new Mock <LibraryContext>();

            mockContext.Setup(x => x.Set <Publisher>()).Returns(mockSet.Object);

            this.service = new PublisherService(mockContext.Object);
            this.service.Delete(this.publisher);
            try
            {
                mockSet.Verify(m => m.Remove(It.IsAny <Publisher>()), Times.Once());
                mockContext.Verify(m => m.SaveChanges(), Times.Once());
            }
            catch (MockException e)
            {
                Assert.Fail(e.Message);
            }
        }
Beispiel #12
0
        public async Task FindBookTraderAsyncShouldReturnTraiderIdIfBookExists()
        {
            //Arrange
            var db = await this.GetDatabase();

            await this.SeedDb(db);

            var authorService    = new AuthorService(db);
            var publisherService = new PublisherService(db);

            var bookService = new BookService(db, authorService, publisherService);

            //Act
            var result = await bookService.FindBookTraderAsync(BookId);

            //Assert
            result
            .Should()
            .BeEquivalentTo(UserId);
        }
        public void Setup()
        {
            var configurationHelper = new ConfigurationHelper();

            _projectId       = configurationHelper.ProjectId;
            _topicId         = $"{configurationHelper.TopicId}-{Guid.NewGuid()}";
            _subscription1Id = $"{configurationHelper.SubscriptionId}-{Guid.NewGuid()}";
            _subscription2Id = $"{configurationHelper.SubscriptionId}-{Guid.NewGuid()}";

            _ackTimeoutInSeconds = 60;

            _topicService        = new TopicService();
            _subscriptionService = new SubscriptionService();
            _publisherService    = new PublisherService();

            _topicService.CreateTopic(_projectId, _topicId);

            _subscriptionService.CreateSubscription(_projectId, _topicId, _subscription1Id, _ackTimeoutInSeconds);
            _subscriptionService.CreateSubscription(_projectId, _topicId, _subscription2Id, _ackTimeoutInSeconds);
        }
        public static async Task <Publisher> CreateValidPublisher()
        {
            var connectionString = ConnectivityService.GetConnectionString("TEMP");
            var context          = new BookOrganizer2DbContext(connectionString);
            var repository       = new PublisherRepository(context);

            var publisherService = new PublisherService(repository);

            var command = new Commands.Create
            {
                Id          = new PublisherId(SequentialGuid.NewSequentialGuid()),
                Name        = "SubPop",
                LogoPath    = @"\\filepath\file.jpg",
                Description = "Best books in the world!"
            };

            await publisherService.Handle(command);

            return(await repository.GetAsync(command.Id));
        }
        public async Task Create_Test()
        {
            // arrange
            var fakeUowProvider  = A.Fake <IUnitOfWorkProvider>();
            var fakeRepoProvider = A.Fake <IPublisherRepositoryProvider>();
            var fakeRepo         = A.Fake <IPublisherRepository>();
            var fakeUow          = A.Fake <IUnitOfWork>();

            A.CallTo(() => fakeUowProvider.Get()).Returns(fakeUow);
            A.CallTo(() => fakeRepoProvider.Get(fakeUow)).Returns(fakeRepo);
            PublisherService service   = new PublisherService(fakeUowProvider, fakeRepoProvider);
            Publisher        publisher = new Publisher("some_publisher");

            // act
            await service.Add(publisher);

            // assert
            A.CallTo(() => fakeRepo.Create(publisher)).MustHaveHappened();
            A.CallTo(() => fakeUow.Dispose()).MustHaveHappened();
        }
        public void GetVideosByPublisher_ShouldntReturnDeletedVideos()
        {
            var publisherService = new PublisherService();
            var publisher        = publisherService.CreateAndRetrievePublisher(new CreatePublisherDto("", "", -1, "", testLibrary.LibraryId));

            var expectedVideos = new List <Video>();

            for (int i = 0; i < 3; ++i)
            {
                var video = CreateAndRetrieveVideo(GetNewVideoDetails(publisher));
                expectedVideos.Add(video);
            }
            var deletedVideo = CreateAndRetrieveVideo(GetNewVideoDetails(publisher));

            repository.DeleteVideo(deletedVideo.VideoId).ConfigureAwait(false);


            var videos = repository.GetVideosByPublisher(publisher.PublisherId, GetFirstPage()).Result.Results;

            CollectionAssert.AreEquivalent(expectedVideos, videos);
        }
        public void CreatePost()
        {
            AutoMapperDataConfig.RegisterMappings();
            PublisherService publisherService = new PublisherService(new PostRepository(), new TagRepository());

            var postDto = new PostDto()
            {
                Body = "Body",
                Title = "Title",
                User = new UserDto()
                {
                    Login = "******"
                },
                Tags = new List<string>
                {
                    "Deus", "Bíblia", "Deus vivo"
                }
            };

            publisherService.Publish(postDto);
        }
Beispiel #18
0
        public async Task EditAsyncShouldFiledIfBookIsNull()
        {
            //Arrange
            var db = await this.GetDatabase();

            await this.SeedDb(db);

            var authorService    = new AuthorService(db);
            var publisherService = new PublisherService(db);

            var bookService = new BookService(db, authorService, publisherService);

            //Act
            var result = await bookService.EditAsync
                             ("sa", BookId, "Title", "Some Author", "Publisher", Category.История, false, 1987, 10, Condition.Отлично, "Български", null, Coverage.Твърди, null);

            //Assert
            result
            .Should()
            .BeFalse();
        }
        public void UpdateVideo_ChangingPublisherToNotNull_ShouldDeleteSeries()
        {
            var publisherService = new PublisherService();
            var publisher        = publisherService.CreateAndRetrievePublisher(new CreatePublisherDto("", "", -1, "", testLibrary.LibraryId));
            var publisher2       = publisherService.CreateAndRetrievePublisher(new CreatePublisherDto("", "", -1, "", testLibrary.LibraryId));

            var seriesService = new SeriesService();
            var series        = seriesService.CreateAndRetrieveSeries(GetNewSeriesDetails());

            var videoDto        = GetNewVideoDetails(testLibrary, publisher, series);
            var videoToUpdateId = repository.CreateVideo(videoDto);
            var videoToUpdate   = repository.GetVideo(videoToUpdateId).Result;

            videoToUpdate.PublisherId = publisher2.PublisherId;
            videoToUpdate.SeriesId    = DatabaseConstants.DEFAULT_ID;
            repository.UpdateVideo(videoToUpdate).ConfigureAwait(false);

            var updatedVideo = repository.GetVideo(videoToUpdateId).Result;

            Assert.AreEqual(publisher2.PublisherId, updatedVideo.PublisherId);
            Assert.AreEqual(DatabaseConstants.DEFAULT_ID, updatedVideo.SeriesId);
        }
Beispiel #20
0
        public async Task TotalAsyncShouldReturnCorrectResults()
        {
            //Arrange
            var db = await this.GetDatabase();

            await this.SeedDb(db);

            var authorService    = new AuthorService(db);
            var publisherService = new PublisherService(db);

            var bookService = new BookService(db, authorService, publisherService);

            //Act
            var result = await bookService.TotalAsync();

            var deletedBook = db.Books.Find(BookId);

            //Assert
            result
            .Should()
            .Be(3);
        }
Beispiel #21
0
        public async Task SearchBookAsyncShouldReturnCorrectResultForSearchInTitlesWithGivenSearchText()
        {
            //Arrange
            var db = await this.GetDatabase();

            await this.SeedDb(db);

            var authorService    = new AuthorService(db);
            var publisherService = new PublisherService(db);

            var bookService = new BookService(db, authorService, publisherService);

            //Act
            var result = await bookService.SearchBookAsync("Title", "first");

            //Assert
            result
            .Should()
            .Match(r => r.ElementAt(0).Id == 1)
            .And
            .HaveCount(1);
        }
Beispiel #22
0
        public PublisherServiceTest()
        {
            _uow = new Mock <IUnitOfWork>();
            var log = new Mock <ILog>();

            _mapper = MapperConfigUi.GetMapper().CreateMapper();
            _sut    = new PublisherService(_uow.Object, _mapper, log.Object);

            _fakePublisherName = "publisher1";
            _fakePublisherId   = Guid.NewGuid();

            _fakePublisher = new Publisher
            {
                Id   = _fakePublisherId,
                Name = _fakePublisherName
            };

            _fakePublishers = new List <Publisher>()
            {
                _fakePublisher
            };
        }
Beispiel #23
0
        public async Task Create_RecordAlreadyExist()
        {
            var param = DateTime.Now.ToString();
            var mock  = new Mock <ILogger>();

            mock.Setup(o => o.Log(param)).Returns(new PublisherDto {
                PublisherName = "test"
            }.PublisherName);

            dataContext.Publishers.Add(new Publisher {
                PublisherId = 1, PublisherName = "LightHouse Publishing"
            });
            await dataContext.SaveChangesAsync();

            var publisherDto = new PublisherDto
            {
                PublisherName = "LightHouse Publishing"
            };

            var service = new PublisherService(dataContext, mock.Object);

            await service.Create(publisherDto);
        }
Beispiel #24
0
        public async Task BooksByCurrentUserAsyncShouldReturnBooksBelongsToTheGivenUserWithValidUserIdOrderedByIdDescending()
        {
            //Arrange
            var db = await this.GetDatabase();

            await this.SeedDb(db);

            var authorService    = new AuthorService(db);
            var publisherService = new PublisherService(db);

            var bookService = new BookService(db, authorService, publisherService);

            //Act
            var result = await bookService.BooksByCurrentUserAsync(UserId);

            //Assert
            result
            .Should()
            .Match(r => r.ElementAt(0).Id == 3 &&
                   r.ElementAt(1).Id == 1)
            .And
            .HaveCount(2);
        }
Beispiel #25
0
 /// <summary>
 /// 初使化
 /// </summary>
 public void Init()
 {
     using (var context = new MyContext())
     {
         //船舶端组件注册
         var component = context.Component.FirstOrDefault(c => c.Type == ComponentType.WEB);
         if (component != null)
         {
             ManagerHelp.ComponentId = component.Id;
             component.Cid           = "";
             context.Update(component);
             context.SaveChanges();
         }
         else
         {
             ManagerHelp.ComponentId = Guid.NewGuid().ToString();
         }
         //获取数据库默认值
         LoadDBValue();
         //组件注册
         InitData();
         //船舶端需要发送缺岗通知
         if (ManagerHelp.IsShipPort)
         {
             LoadNotice();
             //向IPad推送消息
             PublisherService service = new PublisherService();
             PlayerService    player  = new PlayerService();
             SyncAlarmJob     sync    = new SyncAlarmJob();
             sync.SyncAlarmData();
         }
         //定时获取组件信息
         QueryComponent();
         AlarmService alarmService = new AlarmService();
         alarmService.ReviceAlarm();
     }
 }
        public async Task CreateAsyncShouldNotAddToDbPublisherIfHeExist()
        {
            //Arrange
            var db = await this.GetDatabase();

            var publisherService = new PublisherService(db);

            var publisherName = new Publisher {
                Name = "Enigma"
            };

            db.Add(publisherName);

            await db.SaveChangesAsync();

            var publisher = "Enigma";
            //Act
            var result = await publisherService.CreateAsync(publisher);

            //Arrange
            result
            .Should()
            .Equals(1);
        }
Beispiel #27
0
        public async Task AllAsyncOrderByIdAndOrderDirectionDescendingShouldReturnCorrectResult()
        {
            // Arrange
            var db = await this.GetDatabase();

            await this.SeedDb(db);

            var authorService    = new AuthorService(db);
            var publisherService = new PublisherService(db);

            var bookService = new BookService(db, authorService, publisherService);

            // Act
            var result = await bookService.AllAsync("Id", "Descending");

            //Assert
            result
            .Should()
            .Match(r => r.ElementAt(0).Id == 3 &&
                   r.ElementAt(1).Id == 2 &&
                   r.ElementAt(2).Id == 1)
            .And
            .HaveCount(3);
        }
Beispiel #28
0
        public void AddBookEffort()
        {
            // Arrange
            var effortContext = new BookRankingDbContext(Effort.DbConnectionFactory.CreateTransient());
            var mockMapper    = new Mock <IMapper>();

            var bookToReturn = new Book()
            {
            };

            mockMapper.Setup(x => x.Map <Book>(It.IsAny <BookDTO>())).Returns(bookToReturn);

            var publisherService = new PublisherService(effortContext, mockMapper.Object);
            var authorService    = new AuthorService(effortContext, mockMapper.Object);
            var bookService      = new BookService(authorService, publisherService, effortContext, mockMapper.Object);

            // Act
            var bookToAdd = new BookDTO();

            bookService.AddBook(bookToAdd);

            // Assert
            Assert.AreEqual(1, effortContext.Authors.Count());
        }
Beispiel #29
0
 public static void ModifyPublisher(Publisher publisher)
 {
     PublisherService.ModifyPublisher(publisher);
 }
        public void UpdatePost()
        {
            AutoMapperDataConfig.RegisterMappings();
            PublisherService publisherService = new PublisherService(new PostRepository(), new TagRepository());

            var postDto = new PostDto()
            {
                Id = 1,
                Body = "Body 1",
                Title = "Title 1",
                User = new UserDto()
                {
                    Login = "******"
                }
            };

            publisherService.Edit(postDto);

            var postUpdated = publisherService.GetById(1);

            Assert.IsNotNull(postUpdated);

            Assert.AreEqual(postDto.Body, postUpdated.Body);

            Assert.AreEqual(postDto.Title, postUpdated.Title);
        }
 public PublisherController(PublisherService publisherService)
 {
     _publisherService = publisherService;
 }
Beispiel #32
0
 public static IList <Publisher> GetAllPublishers()
 {
     return(PublisherService.GetAllPublishers());
 }
Beispiel #33
0
 public static Publisher GetPublisherById(int id)
 {
     return(PublisherService.GetPublisherById(id));
 }