/// <summary>
 ///     Update a DataPointConfiguration
 /// </summary>
 /// <param name="deviceId">The Device Id</param>
 /// <param name="deviceDataSourceId">The DeviceDataSource Id</param>
 /// <param name="deviceDataSourceInstanceId">The DeviceDataSourceInstance Id</param>
 /// <param name="dataPointConfiguration">The DataPointConfiguration</param>
 /// <param name="cancellationToken">The cancellation token</param>
 /// <returns></returns>
 public async Task UpdateDataPointConfiguration(
     int deviceId,
     int deviceDataSourceId,
     int deviceDataSourceInstanceId,
     DataPointConfiguration dataPointConfiguration,
     CancellationToken cancellationToken = default)
 => await PutAsync(
     $"device/devices/{deviceId}/devicedatasources/{deviceDataSourceId}/instances/{deviceDataSourceInstanceId}/alertsettings/{dataPointConfiguration.Id}",
     dataPointConfiguration,
     cancellationToken).ConfigureAwait(false);
        private DataPointConfiguration DoCreate(NewDataPointConfiguration newDataPointConfiguration)
        {
            var dataPointConfiguration = new DataPointConfiguration
            {
                OfficeId  = newDataPointConfiguration.OfficeId,
                ProgramId = newDataPointConfiguration.ProgramId,
                ProjectId = newDataPointConfiguration.ProjectId,
                DataPointCategoryPropertyId = newDataPointConfiguration.DataPointCategoryPropertyId
            };

            this.Context.DataPointConfigurations.Add(dataPointConfiguration);
            return(dataPointConfiguration);
        }
Beispiel #3
0
        public async Task TestDeleteDataPointConfigurationAsync()
        {
            var dataPointConfiguration = new DataPointConfiguration
            {
                DataPointConfigurationId = 1,
                OfficeId = 1,
                DataPointCategoryPropertyId = 1
            };

            context.DataPointConfigurations.Add(dataPointConfiguration);

            await service.DeleteDataPointConfigurationAsync(dataPointConfiguration.DataPointConfigurationId);

            Assert.AreEqual(0, 0);
        }
Beispiel #4
0
        public async Task TestCreateDataPointConfigurationAsync_DataPointConfigurationAlreadyExists()
        {
            var dataPointConfiguration = new DataPointConfiguration
            {
                OfficeId = 1,
                DataPointCategoryPropertyId = 1
            };

            context.DataPointConfigurations.Add(dataPointConfiguration);

            var         newDataPointConfiguration = new NewDataPointConfiguration(1, null, null, 1);
            Func <Task> act = async() => { await service.CreateDataPointConfigurationAsync(newDataPointConfiguration); };

            act.ShouldThrow <EcaBusinessException>()
            .WithMessage(DataPointConfigurationService.DATA_POINT_CONFIGURATION_ALREADY_EXISTS_ERROR);
        }
Beispiel #5
0
        public async Task TestGetDataPointConfigurationsAsync_OneParentOffice()
        {
            using (ShimsContext.Create())
            {
                var list = new List <SimpleOfficeDTO>();

                var dto1 = new SimpleOfficeDTO
                {
                    OrganizationId     = 1,
                    OrganizationTypeId = OrganizationType.Office.Id,
                    OrganizationType   = OrganizationType.Office.Value,
                    OfficeSymbol       = "eca",
                    Name        = "org 1",
                    Description = "description",
                    Path        = "1",
                    OfficeLevel = 1
                };
                var dto2 = new SimpleOfficeDTO
                {
                    OrganizationId     = 2,
                    OrganizationTypeId = OrganizationType.Office.Id,
                    OrganizationType   = OrganizationType.Office.Value,
                    ParentOrganization_OrganizationId = 1,
                    OfficeSymbol = "eca",
                    Name         = "org 2",
                    Description  = "description",
                    Path         = "1-1",
                    OfficeLevel  = 2
                };
                list.Add(dto1);
                list.Add(dto2);
                System.Data.Entity.Fakes.ShimDbContext.AllInstances.DatabaseGet = (c) =>
                {
                    var shimDb = new System.Data.Entity.Fakes.ShimDatabase();
                    shimDb.SqlQueryOf1StringObjectArray <SimpleOfficeDTO>(
                        (sql, parameters) =>
                    {
                        var shimDbSql          = new System.Data.Entity.Infrastructure.Fakes.ShimDbRawSqlQuery <SimpleOfficeDTO>();
                        shimDbSql.ToArrayAsync = () =>
                        {
                            return(Task.FromResult <SimpleOfficeDTO[]>(list.ToArray()));
                        };
                        return(shimDbSql);
                    }
                        );
                    return(shimDb);
                };
                System.Linq.Fakes.ShimEnumerable.ToArrayOf1IEnumerableOfM0 <SimpleOfficeDTO>((e) =>
                {
                    return(list.ToArray());
                });

                var dataPointCategory = new DataPointCategory
                {
                    DataPointCategoryId   = DataPointCategory.Office.Id,
                    DataPointCategoryName = DataPointCategory.Office.Value
                };

                var dataPointProperty = new DataPointProperty
                {
                    DataPointPropertyId   = DataPointProperty.Themes.Id,
                    DataPointPropertyName = DataPointProperty.Themes.Value
                };

                var dataPointCategoryProperty = new DataPointCategoryProperty
                {
                    DataPointCategoryPropertyId = 1,
                    DataPointCategoryId         = dataPointCategory.DataPointCategoryId,
                    DataPointCategory           = dataPointCategory,
                    DataPointPropertyId         = dataPointProperty.DataPointPropertyId,
                    DataPointProperty           = dataPointProperty
                };

                context.DataPointCategoryProperties.Add(dataPointCategoryProperty);

                var dataPointConfig = new DataPointConfiguration
                {
                    DataPointConfigurationId = 1,
                    OfficeId = 1,
                    DataPointCategoryPropertyId = dataPointCategoryProperty.DataPointCategoryPropertyId
                };

                context.DataPointConfigurations.Add(dataPointConfig);

                var serviceResult = await service.GetDataPointConfigurationsAsync(dto2.OrganizationId, null, null);

                var result = serviceResult.FirstOrDefault();
                Assert.AreEqual(dataPointConfig.DataPointConfigurationId, result.DataPointConfigurationId);
                Assert.AreEqual(dto2.OrganizationId, result.OfficeId);
                Assert.AreEqual(dataPointConfig.DataPointCategoryPropertyId, result.CategoryPropertyId);
                Assert.AreEqual(dataPointCategory.DataPointCategoryId, result.CategoryId);
                Assert.AreEqual(dataPointCategory.DataPointCategoryName, result.CategoryName);
                Assert.AreEqual(dataPointProperty.DataPointPropertyId, result.PropertyId);
                Assert.AreEqual(dataPointProperty.DataPointPropertyName, result.PropertyName);
                Assert.AreEqual(true, result.IsRequired);
                Assert.AreEqual(true, result.IsInherited);
            }
        }
Beispiel #6
0
        public async Task TestGetDataPointConfigurationsAsync_Office()
        {
            using (ShimsContext.Create())
            {
                var list = new List <SimpleOfficeDTO>();
                System.Data.Entity.Fakes.ShimDbContext.AllInstances.DatabaseGet = (c) =>
                {
                    var shimDb = new System.Data.Entity.Fakes.ShimDatabase();
                    shimDb.SqlQueryOf1StringObjectArray <SimpleOfficeDTO>(
                        (sql, parameters) =>
                    {
                        var shimDbSql          = new System.Data.Entity.Infrastructure.Fakes.ShimDbRawSqlQuery <SimpleOfficeDTO>();
                        shimDbSql.ToArrayAsync = () =>
                        {
                            return(Task.FromResult <SimpleOfficeDTO[]>(list.ToArray()));
                        };
                        return(shimDbSql);
                    }
                        );
                    return(shimDb);
                };
                System.Linq.Fakes.ShimEnumerable.ToArrayOf1IEnumerableOfM0 <SimpleOfficeDTO>((e) =>
                {
                    return(list.ToArray());
                });

                var dataPointCategory = new DataPointCategory
                {
                    DataPointCategoryId   = DataPointCategory.Office.Id,
                    DataPointCategoryName = DataPointCategory.Office.Value
                };

                var dataPointProperty = new DataPointProperty
                {
                    DataPointPropertyId   = DataPointProperty.Themes.Id,
                    DataPointPropertyName = DataPointProperty.Themes.Value
                };

                var dataPointCategoryProperty = new DataPointCategoryProperty
                {
                    DataPointCategoryPropertyId = 1,
                    DataPointCategoryId         = dataPointCategory.DataPointCategoryId,
                    DataPointCategory           = dataPointCategory,
                    DataPointPropertyId         = dataPointProperty.DataPointPropertyId,
                    DataPointProperty           = dataPointProperty
                };

                context.DataPointCategoryProperties.Add(dataPointCategoryProperty);

                var dataPointConfig = new DataPointConfiguration
                {
                    DataPointConfigurationId = 1,
                    OfficeId = 1,
                    DataPointCategoryPropertyId = dataPointCategoryProperty.DataPointCategoryPropertyId
                };

                context.DataPointConfigurations.Add(dataPointConfig);

                var serviceResult = await service.GetDataPointConfigurationsAsync(dataPointConfig.OfficeId.Value, null, null);

                var result = serviceResult.FirstOrDefault();
                Assert.AreEqual(dataPointConfig.DataPointConfigurationId, result.DataPointConfigurationId);
                Assert.AreEqual(dataPointConfig.OfficeId, result.OfficeId);
                Assert.AreEqual(dataPointConfig.DataPointCategoryPropertyId, result.CategoryPropertyId);
                Assert.AreEqual(dataPointCategory.DataPointCategoryId, result.CategoryId);
                Assert.AreEqual(dataPointCategory.DataPointCategoryName, result.CategoryName);
                Assert.AreEqual(dataPointProperty.DataPointPropertyId, result.PropertyId);
                Assert.AreEqual(dataPointProperty.DataPointPropertyName, result.PropertyName);
                Assert.AreEqual(true, result.IsRequired);
                Assert.AreEqual(false, result.IsInherited);
            }
        }