Пример #1
0
        public void Given_KnownString_When_GetByStringInvoked_Then_EnumRetrived()
        {
            var enumType = TestEnum.WithDescription1;
            var enumStr  = enumType.ToString();

            var enumTypeRetrived = EnumsHelper.GetByString <TestEnum>(enumStr);

            Assert.AreEqual(enumType, enumTypeRetrived);
        }
Пример #2
0
        public void Given_FullEnumTypeWithDescriptions_When_Add_Then_AllProcessDefinitionWithNameAndDescriptionCreated()
        {
            var builder      = new ProcessDefinitionBuilder <int, TestUndefinedProcesses>();
            var expectedList = EnumsHelper.GetEnumList <TestUndefinedProcesses>();

            builder.Autogenerate();

            Assert.AreEqual(builder.Count, expectedList.Count());
            Assert.IsTrue(builder.Definitions.Any(x => expectedList.Contains(EnumsHelper.GetByString <TestUndefinedProcesses>(x.Name))));
            Assert.IsTrue(builder.Definitions.Any(x => expectedList.Contains(EnumsHelper.GetByDescription <TestUndefinedProcesses>(x.Description))));
        }
Пример #3
0
        public void Given_EnumWithProcessDefinitionAttributes_When_Add_Then_AllProcessDefinitionWithNameDescriptionAndTypeCreated()
        {
            var builder      = new ProcessDefinitionBuilder <int, TestExtraDefinedProcesses>();
            var expectedList = EnumsHelper.GetEnumList <TestExtraDefinedProcesses>();

            builder.Autogenerate();

            Assert.AreEqual(builder.Count, expectedList.Count());
            Assert.IsTrue(builder.Definitions.Any(x => expectedList.Contains(EnumsHelper.GetByString <TestExtraDefinedProcesses>(x.Name))));
            Assert.IsTrue(builder.Definitions.Any(x => expectedList.Contains(EnumsHelper.GetByDescription <TestExtraDefinedProcesses>(x.Description))));
            Assert.IsTrue(builder.Definitions.Any(x => x.Type == Enums.ProcessType.Background));
            Assert.IsTrue(builder.Definitions.Any(x => x.Type == Enums.ProcessType.Batch));
        }
Пример #4
0
        public IActionResult GetCountry(string alphaType, string alphaCode)
        {
            var actionResponse = GetEmptyResponseBuilder <Country>();

            try
            {
                var enumType = EnumsHelper.GetByString <AlphaCodeType>(alphaType);
                actionResponse.SetData(_countryService.Get(enumType, alphaCode));

                return(Ok(actionResponse));
            }
            catch (Exception ex)
            {
                return(Ko(actionResponse, ex));
            }
        }
Пример #5
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity <Execution <TKey> >(entity =>
            {
                entity.ToTable(EXECUTION_TABLENAME, SCHEMA_NAME);

                entity.Property(e => e.Id).ValueGeneratedOnAdd();

                entity.Property(e => e.Status).HasConversion(
                    dtoValue => dtoValue.ToString(),
                    entityValue => EnumsHelper.GetByString <ExecutionStatus>(entityValue)
                    );
                entity.Property(e => e.Result).HasConversion(
                    dtoValue => dtoValue.ToString(),
                    entityValue => EnumsHelper.GetByString <ExecutionResult>(entityValue)
                    );

                entity.HasOne(e => e.ProcessDefinition).WithMany(n => n.Executions).HasForeignKey(e => e.ProcessDefinitionId);
            });

            modelBuilder.Entity <ExecutionEvent <TKey> >(entity =>
            {
                entity.ToTable(EXECUTIONEVENT_TABLENAME, SCHEMA_NAME);

                entity.Property(e => e.Id).ValueGeneratedOnAdd();

                entity.Property(e => e.Status).HasConversion(
                    dtoValue => dtoValue.ToString(),
                    entityValue => EnumsHelper.GetByString <ExecutionStatus>(entityValue)
                    );

                entity.HasOne(e => e.Execution).WithMany(n => n.ExecutionEvents).HasForeignKey(e => e.ExecutionId);
            });

            modelBuilder.Entity <ProcessDefinition <TKey> >(entity =>
            {
                entity.ToTable(PROCESSDEFINITION_TABLENAME, SCHEMA_NAME);

                entity.Property(e => e.Id).ValueGeneratedOnAdd();
                entity.HasIndex(e => e.Name).IsUnique();
            });
        }
Пример #6
0
        public void Given_WrongType_When_GetByStringInvoked_Then_ExceptionThrown()
        {
            var description = "XXX";

            Assert.ThrowsException <ArgumentException>(() => EnumsHelper.GetByString <DateTime>(description));
        }
Пример #7
0
        public void Given_UnknownString_When_GetByStringInvoked_Then_ExceptionThrown()
        {
            var description = "XXX";

            Assert.ThrowsException <ArgumentException>(() => EnumsHelper.GetByString <TestEnum>(description));
        }
Пример #8
0
 public TProcessEnum GetEnumDefinition <TProcessEnum>()
     where TProcessEnum : struct, IConvertible
 {
     return(EnumsHelper.GetByString <TProcessEnum>(this.Name));
 }