private void InitializeTestData(out Game game, out GameViewModel gameViewModel, out Publisher publisher) { var gameBuilder = new GameBuilder(); var publisherBuilder = new PublisherBuilder(); game = gameBuilder.WithId(new Guid("2245390a-6aaa-4191-35f5-08d7223464b8")) .WithKey("c21") .WithName("Cry Souls") .WithDescription("Cry Souls desc") .WithUnitsInStock(10) .WithPrice(10) .WithPublisher("Unknown") .Build(); gameViewModel = new GameViewModel() { Key = "c21", Name = "Cry Souls55", Description = "Cry Souls 4 desc", UnitsInStock = 10, Price = 10, Publisher = "publisher" }; publisher = publisherBuilder.WithCompanyName("Unknown").Build(); }
private void InitializeTestData(out Game game, out Platform platform, out Publisher publisher, out Genre genre) { var genreBuilder = new GenreBuilder(); var gameBuilder = new GameBuilder(); var gamePlatformBuilder = new GamePlatformBuilder(); var publisherBuilder = new PublisherBuilder(); var gameGenreBuilder = new GameGenreBuilder(); var platformTypeBuilder = new PlatformTypeBuilder(); game = gameBuilder.WithId(new Guid("2245390a-6aaa-4191-35f5-08d7223464b8")).WithKey("c21") .WithName("Cry Souls").WithDescription("Cry Souls desc").WithUnitsInStock(10).WithPrice(10).WithPublisher("Unknown").Build(); game.GameGenres = new List <GameGenre> { gameGenreBuilder.WithGenre("Sport").Build() }; game.GamePlatforms = new List <GamePlatform> { gamePlatformBuilder.WithPlatformType("Desktop").Build() }; platform = platformTypeBuilder.WithId(Guid.NewGuid()).WithType("Desktop").Build(); publisher = publisherBuilder.WithCompanyName("Unknown").Build(); genre = genreBuilder.WithName("Sport").WithId(new Guid("1255390a-6aaa-4191-35f5-08d7223464b8")).Build(); }
public void Should_Validate_Publish_With_Excedent_Authors() { var bookBll = Resolve <IBookBll>(); var bookRepository = Resolve <IBookRepository>(); var publisher = new PublisherBuilder().Build(); var authorBuilder = new AuthorBuilder().WithPublisher(publisher); var author = authorBuilder.Build(); var author2 = authorBuilder.Build(); var author3 = authorBuilder.Build(); var author4 = authorBuilder.Build(); var book = new BookBuilder().Build(); var authorBookBuilder = new AuthorBookBuilder().WithBook(book); var authorBook = authorBookBuilder.WithAuthor(author).Build(); var authorBook2 = authorBookBuilder.WithAuthor(author2).Build(); var authorBook3 = authorBookBuilder.WithAuthor(author3).Build(); var authorBook4 = authorBookBuilder.WithAuthor(author4).Build(); var authorsBook = new List <AuthorBookEntity> { authorBook, authorBook2, authorBook3, authorBook4 }; AddEntities(publisher, author, author2, author3, author4, book, authorBook, authorBook2, authorBook3, authorBook4); Action act = () => bookBll.PublishBook(book.Id, new PublishBookRequestDTO { PublishierId = publisher.Id }); act.Should() .Throw <BusinessException>() .WithMessage($"Book can't have more than 3 authors!"); }
public void Should_Validate_Publish_With_Excedent_Authors() { var bookPublishValidator = Resolve <IBookPublishValidator>(); var bookRepository = Resolve <IBookRepository>(); var publisher = new PublisherBuilder().Build(); var authorBuilder = new AuthorBuilder().WithPublisher(publisher); var author = authorBuilder.Build(); var author2 = authorBuilder.Build(); var author3 = authorBuilder.Build(); var author4 = authorBuilder.Build(); var book = new BookBuilder().Build(); var authorBookBuilder = new AuthorBookBuilder().WithBook(book); var authorBook = authorBookBuilder.WithAuthor(author).Build(); var authorBook2 = authorBookBuilder.WithAuthor(author2).Build(); var authorBook3 = authorBookBuilder.WithAuthor(author3).Build(); var authorBook4 = authorBookBuilder.WithAuthor(author4).Build(); var authorsBook = new List <AuthorBookEntity> { authorBook, authorBook2, authorBook3, authorBook4 }; AddEntities(publisher, author, author2, author3, author4, book, authorBook, authorBook2, authorBook3, authorBook4); book = bookRepository.Get(book.Id).FirstOrDefault(); Action act = () => bookPublishValidator.ValidatePublish(book, publisher); act.Should() .Throw <BusinessException>() .WithMessage($"Book can't have more than 3 authors!"); }
public void Should_Validate_Publisher_Different_From_Authors() { var bookBll = Resolve <IBookBll>(); var bookRepository = Resolve <IBookRepository>(); var publisher = new PublisherBuilder().Build(); var anotherPublisher = new PublisherBuilder().Build(); var author = new AuthorBuilder() .WithPublisher(publisher) .Build(); var book = new BookBuilder() .Build(); var authorBook = new AuthorBookBuilder().WithAuthor(author).WithBook(book).Build(); AddEntities(publisher, anotherPublisher, author, book, authorBook); Action act = () => bookBll.PublishBook(book.Id, new PublishBookRequestDTO { PublishierId = anotherPublisher.Id }); act.Should() .Throw <BusinessException>() .WithMessage($"{Environment.NewLine}The publisher of publication's book must be from one of the authors!"); }
public void Should_Validatebook_Already_Published() { var bookPublishValidator = Resolve <IBookPublishValidator>(); var bookRepository = Resolve <IBookRepository>(); var publisher = new PublisherBuilder().Build(); var author = new AuthorBuilder() .WithPublisher(publisher) .Build(); var book = new BookBuilder() .WithPublisher(publisher) .Build(); var authorBook = new AuthorBookBuilder() .WithAuthor(author) .WithBook(book) .Build(); AddEntities(publisher, author, book, authorBook); book = bookRepository.Get(book.Id).FirstOrDefault(); Action act = () => bookPublishValidator.ValidatePublish(book, publisher); act.Should() .Throw <BusinessException>() .WithMessage($"Book ({book.Id}) is already published!"); }
public void Should_Validatebook_Already_Published() { var bookBll = Resolve <IBookBll>(); var bookRepository = Resolve <IBookRepository>(); var publisher = new PublisherBuilder().Build(); var author = new AuthorBuilder() .WithPublisher(publisher) .Build(); var book = new BookBuilder() .WithPublisher(publisher) .Build(); var authorBook = new AuthorBookBuilder() .WithAuthor(author) .WithBook(book) .Build(); AddEntities(publisher, author, book, authorBook); Action act = () => bookBll.PublishBook(book.Id, new PublishBookRequestDTO { PublishierId = publisher.Id }); act.Should() .Throw <BusinessException>() .WithMessage($"Book ({book.Id}) is already published!"); }
public void Should_Validate_Author_Without_Publisher() { var bookPublishValidator = Resolve <IBookPublishValidator>(); var bookRepository = Resolve <IBookRepository>(); var publisher = new PublisherBuilder().Build(); var author = new AuthorBuilder() .Build(); var book = new BookBuilder() .Build(); var authorBook = new AuthorBookBuilder().WithAuthor(author).WithBook(book).Build(); AddEntities(publisher, author, book, authorBook); book = bookRepository.Get(book.Id).FirstOrDefault(); Action act = () => bookPublishValidator.ValidatePublish(book, publisher); act.Should() .Throw <BusinessException>() .WithMessage($"The following authors do not have publishers on his register:{Environment.NewLine}{author.FirstName}" + $"{Environment.NewLine}The publisher of publication's book must be from one of the authors!"); }
public static IQueryable <Publisher> GetPublishersSample() { var publisherBuilder = new PublisherBuilder(); var testPublishers = new List <Publisher> { publisherBuilder .Details .Name("DC Comics") .Created(DateTime.Parse("01.01.1934")) .Description("Some random description.") .Build() }; publisherBuilder = new PublisherBuilder(); testPublishers.Add(publisherBuilder .Details .Name("Marvel Comics") .Created(DateTime.Parse("01.01.1939")) .Description("Another description") .Build()); publisherBuilder = new PublisherBuilder(); testPublishers.Add(publisherBuilder .Details .Name("Dark Horse Comics") .Created(DateTime.Parse("01.01.1986")) .Description("American comic book and manga publisher.") .Build()); return(testPublishers.AsEnumerable().AsQueryable()); }
public void Should_Validate_publisher_Different_From_Authors() { var bookPublishValidator = Resolve <IBookPublishValidator>(); var bookRepository = Resolve <IBookRepository>(); var publisher = new PublisherBuilder().Build(); var anotherPublisher = new PublisherBuilder().Build(); var author = new AuthorBuilder() .WithPublisher(publisher) .Build(); var book = new BookBuilder() .Build(); var authorBook = new AuthorBookBuilder().WithAuthor(author).WithBook(book).Build(); AddEntities(publisher, anotherPublisher, author, book, authorBook); book = bookRepository.Get(book.Id).FirstOrDefault(); Action act = () => bookPublishValidator.ValidatePublish(book, anotherPublisher); act.Should() .Throw <BusinessException>() .WithMessage($"{Environment.NewLine}The publisher of publication's book must be from one of the authors!"); }
public void Should_Validate_Publisher_Different_From_Authors() { _publisher = new PublisherBuilder().Build(); var anotherPublisher = new PublisherBuilder().Build(); var author = new AuthorBuilder() .WithPublisher(_publisher) .Build(); _book = new BookBuilder() .Build(); var authorBook = new AuthorBookBuilder().WithAuthor(author).WithBook(_book).Build(); var authorsBook = new List <AuthorBookEntity> { authorBook }; _book.AuthorsBook = authorsBook; Action act = () => _bookPublishValidator.ValidatePublish(_book, anotherPublisher); act.Should() .Throw <BusinessException>() .WithMessage($"{Environment.NewLine}The publisher of publication's book must be from one of the authors!"); }
/// <summary> /// Sets the partition provider for the message type /// </summary> /// <typeparam name="T"></typeparam> /// <param name="mbb"></param> /// <param name="partitionProvider">Delegate to determine the partition number for an message. Parameter meaning: (message, topic) => partition.</param> /// <remarks>Ensure the implementation is thread-safe.</remarks> /// <returns></returns> public static PublisherBuilder <T> PartitionProvider <T>(this PublisherBuilder <T> mbb, Func <T, string, int> partitionProvider) { Assert.IsNotNull(partitionProvider, () => new ConfigurationMessageBusException("Null value provided")); Func <object, string, int> untypedProvider = (message, topic) => partitionProvider((T)message, topic); mbb.Settings.Properties[KafkaPublisherSettingsExtensions.PartitionProviderKey] = untypedProvider; return(mbb); }
public static IMotorHostBuilder ConfigurePublisher <TOutput>(this IMotorHostBuilder hostBuilder, Action <HostBuilderContext, IPublisherBuilder <TOutput> > action) where TOutput : class { hostBuilder.ConfigureServices((context, collection) => { var consumerBuilder = new PublisherBuilder <TOutput>(collection, context); consumerBuilder.Build(action); }); return(hostBuilder); }
public void Should_Validate_Unpublish() { var publisher = new PublisherBuilder().Build(); var book = new BookBuilder().WithPublisher(publisher).WithPublishDate(DateTime.Now).Build(); Action act = () => _bookBll.UnPublish(book.Id); act.Should() .Throw <EntityNotFoundException>() .WithMessage(new EntityNotFoundException($"Book ({book.Id})").Message); }
public void Should_Publish_Book() { var publisher = new PublisherBuilder().Build(); var book = new BookBuilder().Build(); _publishBookll.Publish(book, publisher); _publishBookValidator.Received(1).ValidatePublish(Arg.Is(book), Arg.Is(publisher)); book.Publishier.Should().BeEquivalentTo(publisher); }
public void Build_MissingProperty_ThrowsException() { var builder = new PublisherBuilder(); var bc = builder .Details .Created(new DateTime(1999, 01, 10)) .Description("Desc"); var ex = Assert.Throws <ValidationException>((() => bc.Build())); Assert.Equal("Publisher name cannot be empty", ex.Message); }
public void Build_NameValidationError_ThrowsException() { var builder = new PublisherBuilder(); var bc = builder .Details .Name("DC") .Created(new DateTime(1999, 01, 01)) .Description("Test desc"); var ex = Assert.Throws <ValidationException>(() => bc.Build()); Assert.Equal("Publisher name is too short.", ex.Message); }
public void Build_ValidCall() { var builder = new PublisherBuilder(); var publisher = builder .Details .Name("DC Comics") .Created(new DateTime(1999, 01, 01)) .Description("Desc") .Build(); Assert.NotNull(publisher); Assert.False(publisher.HasErrors); }
public void Should_Call_Unpublish() { var publisher = new PublisherBuilder().Build(); var book = new BookBuilder().WithPublisher(publisher).WithPublishDate(DateTime.Now).Build(); _repository.Get(Arg.Is(book.Id)).Returns(new List <BookEntity> { book }.AsQueryable()); _bookBll.UnPublish(book.Id); book.Publishier.Should().BeNull(); book.PublishDate.Should().BeNull(); }
public void Should_Unpublish_Book() { var bookBll = Resolve <IBookBll>(); var bookRepository = Resolve <IBookRepository>(); var publisher = new PublisherBuilder().Build(); var book = new BookBuilder().WithPublisher(publisher).WithPublishDate(DateTime.Now).Build(); AddEntities(publisher, book); bookBll.UnPublish(book.Id); book = bookRepository.Get(book.Id).FirstOrDefault(); book.Publishier.Should().BeNull(); book.PublishDate.Should().BeNull(); }
public void Build_ValidCall() { var builder = new SeriesBuilder(); var publisher = new PublisherBuilder() .Details .Name("DC Comics") .Created(new DateTime(1997, 01, 01)) .Build(); var bc = builder .Details .Name("Series") .Description("Desc") .Publisher(publisher) .Build(); Assert.NotNull(bc); }
private void InitializeTestData(out Game game, out Publisher publisher) { var gameBuilder = new GameBuilder(); var publisherBuilder = new PublisherBuilder(); game = gameBuilder.WithId(new Guid("2245390a-6aaa-4191-35f5-08d7223464b8")).WithKey("c21") .WithName("Cry Souls").WithDescription("Cry Souls desc").WithUnitsInStock(10).WithPrice(10).WithPublisher("Unknown").Build(); game.Languages = new List <GameTranslation> { new GameTranslation() }; publisher = publisherBuilder.WithId(Guid.Empty).WithCompanyName("Unknown").Build(); publisher.Languages = new List <PublisherTranslation> { new PublisherTranslation() }; }
public void Build_NameValidationError_ThrowsException() { var builder = new SeriesBuilder(); var publisher = new PublisherBuilder() .Details .Name("DC Comics") .Created(new DateTime(1997, 01, 01)) .Build(); var bc = builder .Details .Publisher(publisher) .Description("Desc") .Name(""); var ex = Assert.Throws <ValidationException>(() => bc.Build()); Assert.Equal("Series name cannot be empty", ex.Message); }
public void Should_Publish_Book() { var publishBookll = Resolve <IPublishBookBll>(); var bookRepository = Resolve <IBookRepository>(); var publisher = new PublisherBuilder().Build(); var author = new AuthorBuilder().WithPublisher(publisher).Build(); var book = new BookBuilder().Build(); var authorBook = new AuthorBookBuilder().WithAuthor(author).WithBook(book).Build(); AddEntities(publisher, book, author, authorBook); publishBookll.Publish(book, publisher); Commit(); book = bookRepository.Get(book.Id).FirstOrDefault(); book.Publishier.Should().BeEquivalentTo(publisher); book.PublishDate.Should().NotBeNull(); }
public KafkaPublisherBuilderExtensionsTest() { ps = new PublisherSettings(); pb = new PublisherBuilder <SomeMessage>(ps); }