Example #1
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);
            }
        }
Example #2
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);
            }
        }