Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
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}
Esempio n. 4
0
        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();
        }
Esempio n. 5
0
        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;
Esempio n. 6
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;