public void GetEntityFileText_passed_normal_entity_creates_expected_text()
        {
            var classNamespace = "Domain.Entities";
            var entity         = CannedGenerator.FakeBasicProduct();

            var fileText = EntityBuilder.GetEntityFileText(classNamespace, entity);

            var expectedText = @"namespace Domain.Entities
{
    using System;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    using Sieve.Attributes;

    public class Product
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Required]
        [Sieve(CanFilter = true, CanSort = false)]
        public int ProductId { get; set; }

        [Sieve(CanFilter = true, CanSort = false)]
        public string Name { get; set; }

        // add-on property marker - Do Not Delete This Comment
    }
}";

            fileText.Should().Be(expectedText);
        }
Beispiel #2
0
        public void GetContextFileText_passed_normal_entity_creates_expected_text()
        {
            var classNamespace = "Infrastructure.Persistence.Contexts";
            var template       = CannedGenerator.FakeBasicApiTemplate();

            var fileText = DbContextBuilder.GetContextFileText(classNamespace, template);

            var expectedText = @"namespace Infrastructure.Persistence.Contexts
{
    using Application.Interfaces;
    using Domain.Entities;
    using Domain.Common;
    using Microsoft.EntityFrameworkCore;
    using Microsoft.EntityFrameworkCore.ChangeTracking;
    using System.Threading;
    using System.Threading.Tasks;

    public class BespokedBikesDbContext : DbContext
    {
        public BespokedBikesDbContext(
            DbContextOptions<BespokedBikesDbContext> options) : base(options) 
        {
        }

        #region DbSet Region - Do Not Delete
        public DbSet<Product> Products { get; set; }
        #endregion
    }
}";

            fileText.Should().Be(expectedText);
        }
Beispiel #3
0
        public void GetContextFileText_passed_normal_entity_creates_expected_text()
        {
            var classNamespace = "Infrastructure.Persistence.Contexts";
            var template       = CannedGenerator.FakeBasicApiTemplate();

            var fileText = DbContextBuilder.GetContextFileText(classNamespace, template.Entities, template.DbContext.ContextName, "", "MyBc");

            var expectedText = @$ "namespace Infrastructure.Persistence.Contexts
{{
    using MyBc.Core.Entities;
    using Microsoft.EntityFrameworkCore;
    using Microsoft.EntityFrameworkCore.ChangeTracking;
    using System.Threading;
    using System.Threading.Tasks;
        public void EntityBuilder_CreateEntity_throws_error_if_file_exists()
        {
            var solutionDirectory = @"c:\myrepo";
            var fileSystem        = new MockFileSystem();

            fileSystem.AddDirectory(solutionDirectory);

            var entity           = CannedGenerator.FakeBasicProduct();
            var expectedFilePath = ClassPathHelper.EntityClassPath(solutionDirectory, $"{entity.Name}.cs").FullClassPath;

            fileSystem.AddFile(expectedFilePath, new MockFileData("content doesn't matter"));

            Assert.Throws <FileAlreadyExistsException>(() => EntityBuilder.CreateEntity(solutionDirectory, entity, fileSystem));
        }
Beispiel #5
0
        public void GetEntityFileText_passed_normal_entity_creates_expected_text()
        {
            var classNamespace  = "Domain.Entities";
            var entity          = CannedGenerator.FakeBasicProduct();
            var tableAnnotation = EntityBuilder.TableAnnotationBuilder(entity);
            var fileText        = EntityBuilder.GetEntityFileText(classNamespace, entity);

            var expectedText = @$ "namespace Domain.Entities
{{
    using System;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    using Sieve.Attributes;

    {tableAnnotation}
        public void EntityBuilder_CreateEntity_createsEntityFile()
        {
            var solutionDirectory = @"c:\myrepo";
            var fileSystem        = new MockFileSystem();

            fileSystem.AddDirectory(solutionDirectory);

            var entity           = CannedGenerator.FakeBasicProduct();
            var expectedFilePath = ClassPathHelper.EntityClassPath(solutionDirectory, $"{entity.Name}.cs").FullClassPath;

            EntityBuilder.CreateEntity(solutionDirectory, entity, fileSystem);

            var exists = fileSystem.FileExists(expectedFilePath);

            exists.Should().BeTrue();
        }
        public void GetEntityFileText_passed_entity_with_default_value_creates_expected_text(string type, string defaultVal, string expectedPropertyText)
        {
            var classNamespace = "Domain.Entities";
            var entity         = CannedGenerator.FakeBasicProduct();

            entity.Properties.Add(new EntityProperty {
                Name = "Test", Type = type, DefaultValue = defaultVal, CanFilter = true, CanSort = true
            });

            var fileText = EntityBuilder.GetEntityFileText(classNamespace, entity);

            var expectedText = @$ "namespace Domain.Entities
{{
    using System;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    using Sieve.Attributes;
Beispiel #8
0
        public void GetControllerFileText_passed_normal_entity_creates_expected_text_without_swagger()
        {
            var classNamespace = "WebApi.Controllers.v1";
            var entity         = CannedGenerator.FakeBasicProduct();

            var fileText = ControllerBuilder.GetControllerFileText(classNamespace, entity, false, new List <Policy>(), "", "");

            var expectedText = @$ "namespace WebApi.Controllers.v1
{{
    using System;
    using System.Collections.Generic;
    using System.Text.Json;
    using Microsoft.AspNetCore.JsonPatch;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.AspNetCore.Authorization;
    using System.Threading.Tasks;
    using .Core.Dtos.Product;
    using .Core.Wrappers;
    using System.Threading;
    using MediatR;
    using static .WebApi.Features.Products.GetProductList;
        public void GetControllerFileText_passed_normal_entity_creates_expected_text()
        {
            var classNamespace = "WebApi.Controllers.v1";
            var entity         = CannedGenerator.FakeBasicProduct();

            var fileText = ControllerBuilder.GetControllerFileText(classNamespace, entity);

            var expectedText = @$ "namespace WebApi.Controllers.v1
{{
    using System;
    using System.Collections.Generic;
    using System.Text.Json;
    using AutoMapper;
    using FluentValidation.AspNetCore;
    using Application.Dtos.Product;
    using Application.Enums;
    using Application.Interfaces.Product;
    using Application.Validation.Product;
    using Domain.Entities;
    using Microsoft.AspNetCore.JsonPatch;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.AspNetCore.Authorization;
    using System.Threading.Tasks;