public void Configure(EntityTypeBuilder <Author> builder) { builder.ToTable("Author").HasKey(k => k.Id); builder.OwnsOne(p => p.Name, p => { p.Property(pp => pp.First).HasColumnName("FirstName").IsRequired().HasMaxLength(50); p.Property(pp => pp.Last).HasColumnName("LastName").IsRequired().HasMaxLength(50); }); builder.Property(p => p.DateOfBirth) .IsRequired() .HasConversion(p => p.Value, p => BirthDate.Create(p).Value); builder.Property(p => p.DateOfDeath) .HasConversion(p => p.Value, p => DeathDate.Create(p).Value); builder.Property(p => p.MainCategory) .IsRequired() .HasMaxLength(50) .HasConversion(p => p.Value, p => MainCategory.Create(p).Value); builder.HasMany(p => p.Books).WithOne(p => p.Author) .OnDelete(DeleteBehavior.Cascade) .Metadata.PrincipalToDependent.SetPropertyAccessMode(PropertyAccessMode.Field); }
public void Customize(IFixture fixture) { fixture.Customizations.Add(new CurrentDateTimeGenerator()); fixture.Register(() => Name.Create(fixture.Create <string>(), fixture.Create <string>()).Value); fixture.Register(() => BirthDate.Create(fixture.Create <DateTimeOffset>().AddDays(-fixture.Create <int>())).Value); fixture.Register(() => DeathDate.Create(fixture.Create <DateTimeOffset>().AddDays(-fixture.Create <int>())).Value); fixture.Register(() => MainCategory.Create(fixture.Create <string>()).Value); }
public void Create_MainCategory_Should_Fail_For_EmptyNullValue(string mainCategory) { //Act var result = MainCategory.Create(mainCategory); //Assert result.IsFailure.Should().BeTrue(); result.Error.Should().Be("Main Category is required."); }
public static async void InitialiseDbForTests(FakeDatabase dbContext) { await dbContext.Authors.AddAsync( new Author( Name.Create("Abdul Rahman", "Shabeek Mohamed").Value, BirthDate.Create(new DateTime(1993, 2, 10)).Value, null, MainCategory.Create("SciFi").Value)); await dbContext.SaveChangesAsync(); }
public void Create_MainCategory_Should_Create_For_ValidValue() { //Arrange var fixture = new Fixture(); var mainCategory = fixture.Create <string>(); //Act var result = MainCategory.Create(mainCategory); //Assert result.IsSuccess.Should().BeTrue(); result.Value.Value.Should().Be(mainCategory.Trim()); }
public void Create_MainCategory_Should_Fail_For_MoreThan50CharacterValue() { //Arrange var fixture = new Fixture(); var mainCategory = string.Join(string.Empty, fixture.CreateMany <string>(2)); //Act var result = MainCategory.Create(mainCategory); //Assert result.IsFailure.Should().BeTrue(); result.Error.Should().Be("Main Category is too long."); }