Ejemplo n.º 1
0
 public static void TestInitialize(TestContext testContext)
 {
     _mockReadObj  = new Mock <IDataReader <DemoEntity> >();
     _mockWriteObj = new Mock <IDataWriter <DemoEntity> >();
     _dataContext  = new DataModelDataContext <DemoEntity>(_mockReadObj.Object, _mockWriteObj.Object);
     _demo         = new DemoEntity();
 }
Ejemplo n.º 2
0
    public Task Test(DemoEntity entity)
    {
        //return Task.CompletedTask;
        var openData = _openService.GetById(1);

        throw new NotImplementedException("Method not Implemented");
    }
Ejemplo n.º 3
0
        public IHttpActionResult Save([FromBody] DemoEntity entity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            return(Ok(Guid.NewGuid()));
        }
Ejemplo n.º 4
0
        public void EncodesIntProp()
        {
            var demo = new DemoEntity()
            {
                IntProp = 42
            };
            var entity = Fac.BuildTableEntity(demo);

            Assert.True(entity.Properties.ContainsKey("IntProp"));
        }
        public IHttpActionResult Get(int id)
        {
            DemoEntity entity = _repo.GetById(id);

            if (entity == null)
            {
                return(NotFound());
            }
            return(Ok(entity));
        }
 public IHttpActionResult Post(DemoModel model)
 {
     if (ModelState.IsValid)
     {
         DemoEntity entity = model.ToEntity();
         _repo.Add(entity);
         return(Ok(entity));
     }
     return(BadRequest());
 }
Ejemplo n.º 7
0
        public void CastsAndEncodesDateTime()
        {
            var demo = new DemoEntity()
            {
                DateProp = DateTime.Now
            };
            var entity = Fac.BuildTableEntity(demo);

            Assert.True(entity.Properties.ContainsKey("DateProp"));
        }
Ejemplo n.º 8
0
        public void EncodesInt64Prop()
        {
            var demo = new DemoEntity()
            {
                LongProp = Convert.ToInt64(42)
            };
            var entity = Fac.BuildTableEntity(demo);

            Assert.True(entity.Properties.ContainsKey("LongProp"));
        }
Ejemplo n.º 9
0
        public void EncodesDoubleProp()
        {
            var demo = new DemoEntity()
            {
                BoolProp   = true,
                DoubleProp = Convert.ToDouble(42)
            };
            var entity = Fac.BuildTableEntity(demo);

            Assert.True(entity.Properties.ContainsKey("DoubleProp"));
        }
Ejemplo n.º 10
0
        public void RetrievesAppropriateBooleanValue()
        {
            var demo = new DemoEntity()
            {
                BoolProp = true
            };

            var entity = Fac.BuildTableEntity(demo);

            Assert.True(entity.Properties["BoolProp"].BooleanValue);
        }
        public void DecodeDates()
        {
            var demo = new DemoEntity()
            {
                DateProp = DateTime.UtcNow
            };
            var entity  = Fac.BuildTableEntity(demo);
            var testVal = (DemoEntity)Fac.RecastEntity(entity, typeof(DemoEntity));

            Assert.Equal(demo.DateProp, testVal.DateProp);
        }
Ejemplo n.º 12
0
        public void EncodesBoolProp()
        {
            var demo = new DemoEntity()
            {
                BoolProp = true
            };

            var entity = Fac.BuildTableEntity(demo);

            Assert.True(entity.Properties.ContainsKey("BoolProp"));
        }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            var sample = new DemoEntity
            {
                TestNumber = 1
            };

            _context.Insert(sample);

            var example = _context.Get <DemoEntity>();
        }
Ejemplo n.º 14
0
        public DemoEntity ToEntity()
        {
            DemoEntity entity = new DemoEntity {
                Id         = Id,
                DemoBool   = DemoBool,
                DemoDate   = DemoDate,
                DemoString = DemoString
            };

            return(entity);
        }
Ejemplo n.º 15
0
        public void AppropriateDateValue()
        {
            var demo = new DemoEntity()
            {
                DateProp = DateTime.UtcNow
            };
            var date    = DateTime.Now.ToUniversalTime();
            var entity  = Fac.BuildTableEntity(demo);
            var testVal = (DemoEntity)Fac.RecastEntity(entity, typeof(DemoEntity));

            Assert.Equal(demo.DateProp, testVal.DateProp);
        }
Ejemplo n.º 16
0
        private void TuWas(ref int x, ref string y, DemoEntity z)
        {
            x = 2;
            y = "3";

            z.MyString = "Jan";

            z = new DemoEntity()
            {
                MyString = "Mattes"
            };
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 异步删除示例实体
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <OperationResult> DeleteDemoEntityAsync(int id)
        {
            id.CheckGreaterThan("id", 0);
            DemoEntity entity = await _demoEntityRepository.GetByKeyAsync(id);

            if (entity == null)
            {
                return(new OperationResult(OperationResultType.QueryNull, "编号为“{0}”的示例实体不存在。".FormatWith(id)));
            }
            return((await _demoEntityRepository.DeleteAsync(entity)) > 0
                ? new OperationResult(OperationResultType.Success, "示例实体“{0}”删除成功。".FormatWith(entity.Name), entity.Name)
                : new OperationResult(OperationResultType.NoChanged));
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 添加示例实体
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public OperationResult AddDemoEntity(DemoEntityDto dto)
        {
            dto.CheckNotNull("dto");
            if (CheckDemoEntityName(dto.Name, CheckExistsType.Insert))
            {
                return(new OperationResult(OperationResultType.ValidError, "名称为“{0}”的示例实体已存在,不能重复添加。".FormatWith(dto.Name)));
            }
            DemoEntity entity = Mapper.Map <DemoEntity>(dto);

            return(_demoEntityRepository.Insert(entity) > 0
                ? new OperationResult(OperationResultType.Success, "示例实体“{0}”添加成功。".FormatWith(entity.Name))
                : new OperationResult(OperationResultType.NoChanged));
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 异步修改示例实体
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <OperationResult> UpdateDemoEntityAsync(DemoEntityDto dto)
        {
            dto.CheckNotNull("dto");
            if (await CheckDemoEntityNameAsync(dto.Name, CheckExistsType.Update, dto.Id))
            {
                return(new OperationResult(OperationResultType.ValidError, "名称为“{0}”的示例实体已存在,不能重复添加。".FormatWith(dto.Name)));
            }
            DemoEntity entity = await _demoEntityRepository.GetByKeyAsync(dto.Id);

            entity = Mapper.Map(dto, entity);
            return((await _demoEntityRepository.UpdateAsync(entity)) > 0
                ? new OperationResult(OperationResultType.Success, "示例实体“{0}”更新成功。".FormatWith(entity.Name))
                : new OperationResult(OperationResultType.NoChanged));
        }
        public UpdateStatementSource(int id, DemoEntity entity)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("UPDATE [dbo].[Demo] ");
            sb.AppendLine("SET DemoString = @demoString ");
            sb.Append(",DemoBool = @demoBool ");
            sb.AppendLine("WHERE Id = @id ");

            _command = sb.ToString();

            _params.Add(new SqlParameter("@demoString", entity.DemoString));
            _params.Add(new SqlParameter("@demoBool", entity.DemoBool));
            _params.Add(new SqlParameter("@demoDate", entity.DemoBool));
        }
Ejemplo n.º 21
0
        /// <summary>
        /// 定义种子数据初始化过程
        /// </summary>
        /// <param name="context">数据上下文</param>
        public void Action(DbContext context)
        {
            DemoEntity entity = new DemoEntity()
            {
                Name        = "示例实体",
                DemoDetails = new List <DemoDetail>()
                {
                    new DemoDetail()
                    {
                        Content = "示例子项一"
                    },
                    new DemoDetail()
                    {
                        Content = "示例子项二"
                    }
                }
            };

            context.Set <DemoEntity>().Add(entity);
        }
Ejemplo n.º 22
0
    public async Task Save(DemoEntity entity, int id = 0)
    {
        _logger.LogInformation("Method save called");

        if (id == 0)
        {
            await _baseRepository.Add(entity);
        }
        else
        {
            var demo = await _baseRepository
                       .GetObjectAsync <DemoEntity>(x => x.Id == id);

            demo.Presenter   = entity.Presenter;
            demo.Text        = entity.Text;
            demo.Description = entity.Description;

            await _baseRepository.Update(demo);
        }
    }
Ejemplo n.º 23
0
        public InsertStatementSource(DemoEntity entity)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("INSERT INTO [dbo].[DistanceReports] ");
            sb.AppendLine("(DemoString, DemoBool, DemoDate) ");
            sb.AppendLine("VALUES ");
            sb.AppendLine("(@demoString, @demoBool, @demoDate) ");
            sb.AppendLine("SET @identity = SCOPE_IDENTITY() ");

            _command = sb.ToString();

            Parameters.Add(new SqlParameter("@demoString", entity.DemoString));
            Parameters.Add(new SqlParameter("@demoBool", entity.DemoBool));
            Parameters.Add(new SqlParameter("@demoDate", entity.DemoDate));

            SqlParameter identity = new SqlParameter("@identity", SqlDbType.Int, 4);

            identity.Direction = ParameterDirection.Output;
            Parameters.Add(identity);
        }
Ejemplo n.º 24
0
        /*
         * @brief 當實體從群組中移除
         */
        private void OnEntityRemoveHandler(IGroup <DemoEntity> group, DemoEntity entity)
        {
            component = null;

            Console.WriteLine($"demo entity: {entity} remove from group");
        }
Ejemplo n.º 25
0
        /*
         * @brief 當實體加入到群組中
         */
        private void OnEntityAddHandler(IGroup <DemoEntity> group, DemoEntity entity)
        {
            component = (ComponentA)entity.GetComponent(ComponentA.Id);

            Console.WriteLine($"demo entity: {entity} add to group");
        }
        public static void Init(TestContext context)
        {
            // Wire up test secrets.
            _secrets = TestsBase.InitSecrets();

            // Get a data client, helping us actually Read data, too.
            _dataClient = LawDataClientHelper.GetLawDataClient(
                _secrets.LawSecrets.LawId,
                _secrets.LawPrincipalCredentials.ClientId,
                _secrets.LawPrincipalCredentials.ClientSecret,
                _secrets.LawPrincipalCredentials.Domain)
                          .Result;

            // Set up unique identifiers for the tests. This helps us query the Log Analytics Workspace for our specific messages, and ensure the count and properties are correctly shipped to the logs.
            testIdentifierEntries       = $"test-id-{Guid.NewGuid()}";
            testIdentifierEntry         = $"test-id-{Guid.NewGuid()}";
            testIdentifierEncodingEntry = $"test-id-{Guid.NewGuid()}-ÅÄÖ@~#$%^&*()123";
            testIdentifierNullableEntry = $"test-id-{Guid.NewGuid()}";
            testIdentifierLogTypeEntry  = $"test-id-{Guid.NewGuid()}";
            diTestId = $"test-id-di-{Guid.NewGuid()}";


            // Initialize the LAW Client.
            LogAnalyticsClient logger = new LogAnalyticsClient(
                workspaceId: _secrets.LawSecrets.LawId,
                sharedKey: _secrets.LawSecrets.LawKey);

            // Test 1 prep: Push a collection of entities to the logs.
            List <DemoEntity> entities = new List <DemoEntity>();

            for (int ii = 0; ii < 12; ii++)
            {
                entities.Add(new DemoEntity
                {
                    Criticality  = "e2ecriticality",
                    Message      = testIdentifierEntries,
                    SystemSource = "e2etest",
                    Priority     = int.MaxValue - 1
                });
            }
            logger.SendLogEntries(entities, "endtoendlogs").Wait();


            // Test 2 prep: Send a single entry to the logs.
            logger.SendLogEntry(new DemoEntity
            {
                Criticality  = "e2ecriticalitysingleentry",
                Message      = testIdentifierEntry,
                SystemSource = "e2etestsingleentry",
                Priority     = int.MinValue + 1
            }, "endtoendlogs");

            // Since it takes a while before the logs are queryable, we'll sit tight and wait for a few minutes before we launch the retrieval-tests.

            // Test 3 prep: Verify that different encoding types work
            var encodingTestEntity = new DemoEntity
            {
                Criticality  = "e2ecriticalityencoding",
                Message      = $"{testIdentifierEncodingEntry}", // Special encoding test.
                SystemSource = "e2etestencoding",
                Priority     = int.MaxValue - 10000
            };

            logger.SendLogEntry(encodingTestEntity, "endtoendlogs");

            // Test 4 prep: Verify that nullable entries work
            var nullableTestEntity = new NullableDemoEntity
            {
                Message   = $"{testIdentifierNullableEntry}",
                NoValue   = null,
                WithValue = int.MaxValue - 20000
            };

            logger.SendLogEntry(nullableTestEntity, "endtoendlogs");


            // Test 5 prep: Verify we can use AlphaNum + Underscore for Log-Type.
            var logTypeTestEntity = new DemoEntity
            {
                Criticality  = "Critical",
                Message      = testIdentifierLogTypeEntry,
                Priority     = int.MaxValue - 1,
                SystemSource = "logtypetest"
            };

            logger.SendLogEntry(logTypeTestEntity, "log_name_123");

            //
            // DI LOGGER
            //
            var provider = new ServiceCollection()
                           .AddLogAnalyticsClient(c =>
            {
                c.WorkspaceId = _secrets.LawSecrets.LawId;
                c.SharedKey   = _secrets.LawSecrets.LawKey;
            }).BuildServiceProvider();

            var diLogger = provider.GetRequiredService <LogAnalyticsClient>();

            // Send a log entry to verify it works.
            diLogger.SendLogEntry(new DemoEntity
            {
                Criticality  = "e2ecritical",
                Message      = diTestId,
                SystemSource = "e2ewithdi",
                Priority     = int.MinValue + 1
            }, "endtoendwithdilogs");


            // Unfortunately, from the time we send the logs, until they appear in LAW, takes a few minutes.
            Thread.Sleep(8 * 1000 * 60);
        }
Ejemplo n.º 27
0
 public static void TestInitialize(TestContext testContext)
 {
     _demoEntity        = new DemoEntity();
     _mockObj           = new Mock <IDataContext <DemoEntity> >();
     _genericRepository = new GenericRepository <DemoEntity>(_mockObj.Object);
 }
        public static void Init(TestContext context)
        {
            // Wire up test secrets.
            _secrets = InitSecrets();

            // Get a data client, helping us actually Read data, too.
            _dataClient = GetLawDataClient(
                _secrets.LawSecrets.LawId,
                _secrets.LawPrincipalCredentials.ClientId,
                _secrets.LawPrincipalCredentials.ClientSecret,
                _secrets.LawPrincipalCredentials.Domain)
                          .Result;

            // Set up unique identifiers for the tests. This helps us query the Log Analytics Workspace for our specific messages, and ensure the count and properties are correctly shipped to the logs.
            testIdentifierEntries       = $"test-id-{Guid.NewGuid()}";
            testIdentifierEntry         = $"test-id-{Guid.NewGuid()}";
            testIdentifierEncodingEntry = $"test-id-{Guid.NewGuid()}-ÅÄÖ@~#$%^&*()123";
            testIdentifierNullableEntry = $"test-id-{Guid.NewGuid()}";

            // Initialize the LAW Client.
            LogAnalyticsClient logger = new LogAnalyticsClient(
                workspaceId: _secrets.LawSecrets.LawId,
                sharedKey: _secrets.LawSecrets.LawKey);

            // Test 1 prep: Push a collection of entities to the logs.
            List <DemoEntity> entities = new List <DemoEntity>();

            for (int ii = 0; ii < 12; ii++)
            {
                entities.Add(new DemoEntity
                {
                    Criticality  = "e2ecriticality",
                    Message      = testIdentifierEntries,
                    SystemSource = "e2etest",
                    Priority     = int.MaxValue - 1
                });
            }
            logger.SendLogEntries(entities, "endtoendlogs").Wait();


            // Test 2 prep: Send a single entry to the logs.
            logger.SendLogEntry(new DemoEntity
            {
                Criticality  = "e2ecriticalitysingleentry",
                Message      = testIdentifierEntry,
                SystemSource = "e2etestsingleentry",
                Priority     = int.MinValue + 1
            }, "endtoendlogs");

            // Since it takes a while before the logs are queryable, we'll sit tight and wait for a few minutes before we launch the retrieval-tests.

            // Test 3 prep: Verify that different encoding types work
            var encodingTestEntity = new DemoEntity
            {
                Criticality  = "e2ecriticalityencoding",
                Message      = $"{testIdentifierEncodingEntry}", // Special encoding test.
                SystemSource = "e2etestencoding",
                Priority     = int.MaxValue - 10000
            };

            logger.SendLogEntry(encodingTestEntity, "endtoendlogs");

            // Test 4 prep: Verify that nullable entries work
            var nullableTestEntity = new NullableDemoEntity
            {
                Message   = $"{testIdentifierNullableEntry}",
                NoValue   = null,
                WithValue = int.MaxValue - 20000
            };

            logger.SendLogEntry(nullableTestEntity, "endtoendlogs");


            Thread.Sleep(6 * 1000 * 60);
        }
 public void ArrangeData(DemoEntity entity = null)
 {
     _testData.DemoEntity = entity;
 }