Пример #1
0
        public void TestNewCurve()
        {
            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                var repository = new CurveRepository(context);

                var details = repository.CurveDetails();

                var newChild = repository.Add(null);
                newChild.Name = "New Curve Test";

                newChild.TargetSystem = context.TargetSystems.Find(1);
                newChild.CurveFamily = context.CurveFamilies.Find(1);

                Assert.AreEqual(EntityStatus.Unapproved, newChild.Status);
                Assert.AreEqual(EntityStatus.Unapproved, newChild.Curve.Status);

                AggregatedValidationResult result = ValidationManager.Context.Validate(newChild);
                Assert.AreEqual(Status.Success, result.StatusCode);
                newChild.Approve(context.UserName);
                context.CurveDetails.Add(newChild);
                repository.SaveChanges();
            }

            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                var saved = context.CurveDetails.Single(x => x.Name == "New Curve Test");

                Assert.AreEqual(EntityStatus.Approved, saved.Status);
            }
        }
Пример #2
0
        internal static void AddDimItemGroups(ScenarioGeneratorModel context)
        {
            DateTime now = context.AsOfDate;

            RiskFactorDimItemGroup group = new RiskFactorDimItemGroup() { Name="Short Term Tenors", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "A", Latest = true };
            RiskFactorDimType type = context.RiskFactorDimTypes.Where(x => x.Name == "Tenor").First();
            group.RiskFactorDimType = type;
            context.RiskFactorDimItemGroups.Add(group);

            group = new RiskFactorDimItemGroup() { Name = "Long Term Tenors", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "A", Latest = true };
            type = context.RiskFactorDimTypes.Where(x => x.Name == "Tenor").First();
            group.RiskFactorDimType = type;
            context.RiskFactorDimItemGroups.Add(group);

            group = new RiskFactorDimItemGroup() { Name = "Asian Currencies", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "A", Latest = true };
            type = context.RiskFactorDimTypes.Where(x => x.Name == "Currency").First();
            group.RiskFactorDimType = type;
            context.RiskFactorDimItemGroups.Add(group);

            group = new RiskFactorDimItemGroup() { Name = "European Countries", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "A", Latest = true };
            type = context.RiskFactorDimTypes.Where(x => x.Name == "Country").First();
            group.RiskFactorDimType = type;
            context.RiskFactorDimItemGroups.Add(group);

            context.SaveChanges();
        }
Пример #3
0
        public void Add()
        {
            using (var ScenGenContext = new ScenarioGeneratorModel("UnitTestUser", Connection))
            {
                ScenGenContext.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                var record = new RiskFactorDimension();
                var item = new RiskFactorDimensionDetail();
                record.RiskFactorDimensionDetails.Add(item);
                item.Name = "XXX";

                 var dimType = new RiskFactorDimType();
                dimType.Name = "XXX";
                item.RiskFactorDimType = dimType;

                ScenGenContext.RiskFactorDimensionDetails.Add(item);
                ScenGenContext.SaveChanges();

                var result = ScenGenContext.RiskFactorDimensions.Include("RiskFactorDimType").Include("RiskFactorDimensionDetail").Where(x => x.RiskFactorDimensionDetail.Name == "XXX").ToList();

                Assert.AreEqual(1, result.Count());
                Assert.IsNotNull(result[0].RiskFactorDimensionDetail);
                Assert.IsNotNull(result[0].RiskFactorDimensionDetail.RiskFactorDimType);
            }
        }
Пример #4
0
        public void TestEditRiskFactorTypeGroup()
        {
            RiskFactorTypeGroup group;
            string name = "Edit Risk Factor Type Group Test";
            int groupId = 1;

            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                RiskFactorTypeGroupRepository repository = new RiskFactorTypeGroupRepository(context);

                group = repository.RiskFactorTypeGroups().Where(g => g.RiskFactorTypeGroupID == groupId).FirstOrDefault();
                group.Name = name;

                repository.SaveChanges();
            }

            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                RiskFactorTypeGroupRepository repository = new RiskFactorTypeGroupRepository(context);
                group = repository.RiskFactorTypeGroups().Where(g => g.Name == name).FirstOrDefault();

                Assert.AreEqual(groupId, group.RiskFactorTypeGroupID);

            }
        }
Пример #5
0
        public void TestHierarchyMove()
        {
            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                var repository = new CurveFamillyRepository(context);

                var parent = context.CurveFamilies.Single(x => x.Name=="LBG");
                var child = parent.CurveFamilyChildren.First();

                var newParent = repository.Add(parent);
                newParent.Name = "New Curve Familly Parent";
                repository.SaveChanges();

                Assert.IsTrue(repository.Move(child, newParent));
                Assert.AreEqual(child.CurveFamilyParent.Name, newParent.Name);

                repository.SaveChanges();

                var saved = context.CurveFamilies.Single(x => x.Name == "New Curve Familly Parent");

                Assert.IsTrue(saved.CurveFamilyChildren.Count > 0);
            }
        }
Пример #6
0
        public void TestGetRiskFactorType()
        {
            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                RiskFactorType main = context.RiskFactorTypes.Find(1);
                RiskFactorTypeDetail detail = main.RiskFactorTypeDetail;

                Assert.AreEqual(1, detail.RiskFactorTypeID);

            }
        }
Пример #7
0
        internal static void Read(ScenarioGeneratorModel context)
        {
            context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

            var list = context.TargetSystems;

            Console.WriteLine("\n\n*****Target Systems*****");

            foreach (TargetSystem item in list)
            {
                Console.WriteLine(item.Representation);
            }
        }
Пример #8
0
        public void Add()
        {
            using (var ScenGenContext = new ScenarioGeneratorModel(UserName, Connection))
            {
                ScenGenContext.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                var item = new RiskFactorDimType();
                item.Name = "RiskFactorDimTypeXXX";

                ScenGenContext.RiskFactorDimTypes.Add(item);
                ScenGenContext.SaveChanges();

                Assert.AreEqual(ScenGenContext.RiskFactorDimTypes.Where(x => x.Name == "RiskFactorDimTypeXXX").Count(),1);
            }
        }
Пример #9
0
        internal static void Add(ScenarioGeneratorModel context)
        {
            DateTime now = context.AsOfDate;

            var parent = new TargetSystem() { Name = "CRE", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.TargetSystems.Add(parent);

            var item = new TargetSystem() { Name = "CRE (version 2)", StartTime = now.AddDays(-100), EndTime = now.AddDays(-50), CreatedAt = now.AddDays(-120), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", ModifiedAt = now.AddDays(-110), ModifiedBy = "C", Latest = false };
            context.TargetSystems.Add(item);

            var system = new TargetSystem() { Name = "Simra", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.TargetSystems.Add(system);

            context.SaveChanges();
        }
Пример #10
0
        public void TestRequiredAttributes()
        {
            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                var repository = new TargetSystemRepository(context);

                var parent = context.TargetSystems.Find(1);
                parent.Name = "";

                AggregatedValidationResult result = ValidationManager.Context.Validate(parent);
                Assert.AreEqual(Status.Failure, result.StatusCode);
            }
        }
Пример #11
0
        public void TestRequiredAttributes()
        {
            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                var repository = new CurveRepository(context);

                var newChild = repository.Add(null);
                newChild.Name = "New Curve Test1";
                context.CurveDetails.Add(newChild);

                AggregatedValidationResult result = ValidationManager.Context.Validate(newChild);
                Assert.AreEqual(Status.Failure, result.StatusCode);
            }
        }
Пример #12
0
        public void TestGetRiskFactorTypeGroup()
        {
            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                Assert.AreEqual(4, context.RiskFactorTypeGroups.ToList().Count());

                RiskFactorTypeGroup rftg = context.RiskFactorTypeGroups.Find(1);
                Assert.AreEqual(3, rftg.RiskFactorTypeGroupChildren.Count());

                RiskFactorTypeGroup rftgc = context.RiskFactorTypeGroups.Find(2);
                Assert.AreEqual(0, rftgc.RiskFactorTypeGroupChildren.Count());

            }
        }
Пример #13
0
        public void TestMoveRiskFactorTypeGroup()
        {
            RiskFactorTypeGroup child;
            RiskFactorTypeGroup parent;
            RiskFactorTypeGroup newParent;

            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                RiskFactorTypeGroupRepository repository = new RiskFactorTypeGroupRepository(context);

                child = repository.RiskFactorTypeGroups().Where(g => g.RiskFactorTypeGroupID == 3).FirstOrDefault();
                parent = repository.RiskFactorTypeGroups().Where(g => g.RiskFactorTypeGroupID == 1).FirstOrDefault();
                newParent = repository.RiskFactorTypeGroups().Where(g => g.RiskFactorTypeGroupID == 2).FirstOrDefault();

                Assert.AreEqual(parent, child.RiskFactorTypeGroupParent);

                repository.Move(child, newParent);
                repository.SaveChanges();

            }

            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                RiskFactorTypeGroupRepository repository = new RiskFactorTypeGroupRepository(context);

                child = repository.RiskFactorTypeGroups().Where(g => g.RiskFactorTypeGroupID == 3).FirstOrDefault();
                parent = repository.RiskFactorTypeGroups().Where(g => g.RiskFactorTypeGroupID == 1).FirstOrDefault();
                newParent = repository.RiskFactorTypeGroups().Where(g => g.RiskFactorTypeGroupID == 2).FirstOrDefault();

                Assert.AreEqual(newParent, child.RiskFactorTypeGroupParent);

                Assert.AreEqual(UserName, child.ModifiedBy);
                Assert.AreEqual(DateTime.MinValue, child.StartTime);
                Assert.AreEqual(DateTime.MaxValue, child.EndTime);
                Assert.AreEqual(true, child.Latest);

            }
        }
Пример #14
0
        public void TestNew()
        {
            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                var repository = new TargetSystemRepository(context);
                var parent = repository.Add(null);
                parent.Name = "New TargetSystem";

                Assert.AreEqual(EntityStatus.ApprovedInSession, parent.Status);
                repository.SaveChanges();
            }

            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                var saved = context.TargetSystems.Single(x => x.Name == "New TargetSystem");
                Assert.AreEqual(EntityStatus.Approved, saved.Status);
            }
        }
Пример #15
0
        public void TestSaveNewRiskFactorTypeGroup()
        {
            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);
                string testName = "New Risk Factor Type Group";

                RiskFactorTypeGroup rftg = new RiskFactorTypeGroup();
                rftg.Default(UserName);
                context.RiskFactorTypeGroups.Add(rftg);
                rftg.Name = testName;

                context.SaveChanges();

                Assert.AreEqual(1, context.RiskFactorTypeGroups.Where(x => x.Name == testName).Count());
                Assert.AreEqual(DateTime.MinValue, rftg.StartTime);
                Assert.AreEqual(DateTime.MaxValue, rftg.EndTime);

            }
        }
Пример #16
0
        public void TestApproval()
        {
            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                var repository = new CurveFamillyRepository(context);

                var parent = context.CurveFamilies.Single(x => x.Name == "LBG");

                var newChild = repository.Add(parent);
                newChild.Name = "New Curve Child";
                repository.SaveChanges();

                var saved = context.CurveFamilies.Single(x => x.Name == "New Curve Child");

                Assert.AreEqual(EntityStatus.ApprovedInSession, saved.Status);
                repository.SaveChanges();
                saved = context.CurveFamilies.Single(x => x.Name == "New Curve Child");
                Assert.AreEqual(context.UserName, saved.ApprovedBy);
            }
        }
Пример #17
0
        internal static void Read(ScenarioGeneratorModel context)
        {
            context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

            var types = context.RiskFactorDimTypes;
            Console.WriteLine("\n\n*****Risk Dim Types *****");
            foreach (RiskFactorDimType type in types)
            {
                Console.WriteLine(type.Representation);
            }

            var list = context.RiskFactorDimensionDetails;
            Console.WriteLine("\n\n*****Risk Dimensions*****");
            foreach (RiskFactorDimensionDetail detail in list)
            {
                Console.WriteLine(detail.Representation);
            }
        }
Пример #18
0
        public void TestSaveRiskFactorType()
        {
            string name = "Risk Factor Test Name";
            RiskFactorType main;
            RiskFactorTypeDetail detail;
            RiskFactorTypeGroup group;

            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                group = context.RiskFactorTypeGroups.Find(2);

                main = new RiskFactorType();
                main.Default(UserName);
                context.RiskFactorTypes.Add(main);
                detail = new RiskFactorTypeDetail();
                detail.Default(UserName);
                main.RiskFactorTypeDetails.Add(detail);
                detail.Name = name;
                detail.RiskFactorTypeGroupID = group.RiskFactorTypeGroupID;

                context.SaveChanges();
            }

            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                detail = context.RiskFactorTypeDetails.Where(a => a.Name == name).FirstOrDefault();
                Assert.AreEqual(name, detail.Name);
                Assert.AreEqual(true, detail.Latest);
                Assert.AreEqual(DateTime.MinValue, detail.StartTime);
                Assert.AreEqual(DateTime.MaxValue, detail.EndTime);
                Assert.AreEqual(EntityStatus.Unapproved, detail.Status);

                main = detail.RiskFactorType;
                Assert.AreEqual(true, main.Latest);
                Assert.AreEqual(DateTime.MinValue, main.StartTime);
                Assert.AreEqual(DateTime.MaxValue, main.EndTime);
                Assert.AreEqual(DateTime.MaxValue, main.EndTime);
                Assert.AreEqual(EntityStatus.Unapproved, main.Status);

            }
        }
Пример #19
0
        internal static void AddDimItems(ScenarioGeneratorModel context)
        {
            DateTime now = context.AsOfDate;
            var riskFactorDimType = context.RiskFactorDimTypes.Where(x => x.Name == "Tenor").First();

            var main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            var detail = new RiskFactorDimItemDetail() { Name = "1D", Ordinal = 1,  StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "2D", Ordinal=2, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "3D", Ordinal = 3, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "4D", Ordinal = 4, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "5D", Ordinal = 5, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "1W", Ordinal = 7, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            riskFactorDimType = context.RiskFactorDimTypes.Where(x => x.Name == "Currency").First();
            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "EUR", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "GBP", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "USD", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "AUD", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "JPY", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "HKD", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "TWD", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "PLN", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            riskFactorDimType = context.RiskFactorDimTypes.Where(x => x.Name == "Country").First();

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "France", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "Germany", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "Italy", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() { Name = "Spain", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            main = new RiskFactorDimItem() { RiskFactorDimType = riskFactorDimType, StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            context.RiskFactorDimItems.Add(main);
            detail = new RiskFactorDimItemDetail() {  Name = "Portugal", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            main.RiskFactorDimItemDetails.Add(detail);

            context.SaveChanges();
        }
Пример #20
0
        internal static void AddDimItemGroupMembers(ScenarioGeneratorModel context)
        {
            DateTime now = context.AsOfDate;
            RiskFactorDimItemGroup group;
            RiskFactorDimItemGroupMember member;

            group = context.RiskFactorDimItemGroups.Where(g => g.Name == "European Countries").First();

            member = new RiskFactorDimItemGroupMember() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "A", Latest = true };
            member.RiskFactorDimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "Spain").First().RiskFactorDimItem;
            group.RiskFactorDimItemGroupMembers.Add(member);

            member = new RiskFactorDimItemGroupMember() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "A", Latest = true };
            member.RiskFactorDimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "Italy").First().RiskFactorDimItem;
            group.RiskFactorDimItemGroupMembers.Add(member);

            member = new RiskFactorDimItemGroupMember() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "A", Latest = true };
            member.RiskFactorDimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "Germany").First().RiskFactorDimItem;
            group.RiskFactorDimItemGroupMembers.Add(member);

            group = context.RiskFactorDimItemGroups.Where(g => g.Name == "Short Term Tenors").First();

            member = new RiskFactorDimItemGroupMember() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "A", Latest = true };
            member.RiskFactorDimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "1D").First().RiskFactorDimItem;
            group.RiskFactorDimItemGroupMembers.Add(member);

            member = new RiskFactorDimItemGroupMember() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "A", Latest = true };
            member.RiskFactorDimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "2D").First().RiskFactorDimItem;
            group.RiskFactorDimItemGroupMembers.Add(member);

            member = new RiskFactorDimItemGroupMember() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "A", Latest = true };
            member.RiskFactorDimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "3D").First().RiskFactorDimItem;
            group.RiskFactorDimItemGroupMembers.Add(member);

            member = new RiskFactorDimItemGroupMember() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "A", Latest = true };
            member.RiskFactorDimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "4D").First().RiskFactorDimItem;
            group.RiskFactorDimItemGroupMembers.Add(member);

            member = new RiskFactorDimItemGroupMember() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "A", Latest = true };
            member.RiskFactorDimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "5D").First().RiskFactorDimItem;
            group.RiskFactorDimItemGroupMembers.Add(member);

            member = new RiskFactorDimItemGroupMember() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "A", Latest = true };
            member.RiskFactorDimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "1W").First().RiskFactorDimItem;
            group.RiskFactorDimItemGroupMembers.Add(member);

            group = context.RiskFactorDimItemGroups.Where(g => g.Name == "Asian Currencies").First();

            member = new RiskFactorDimItemGroupMember() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "A", Latest = true };
            member.RiskFactorDimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "JPY").First().RiskFactorDimItem;
            group.RiskFactorDimItemGroupMembers.Add(member);

            member = new RiskFactorDimItemGroupMember() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "A", Latest = true };
            member.RiskFactorDimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "HKD").First().RiskFactorDimItem;
            group.RiskFactorDimItemGroupMembers.Add(member);

            member = new RiskFactorDimItemGroupMember() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-100), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "A", Latest = true };
            member.RiskFactorDimItem = context.RiskFactorDimItemDetails.Where(i => i.Name == "TWD").First().RiskFactorDimItem;
            group.RiskFactorDimItemGroupMembers.Add(member);

            context.SaveChanges();
        }
Пример #21
0
        internal static void Read(ScenarioGeneratorModel context)
        {
            context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

            var list = context.RiskFactorDimItemDetails;

            Console.WriteLine("\n\n*****Risk Factor Dim Item Details*****");

            foreach (RiskFactorDimItemDetail item in list)
            {
                Console.WriteLine(item.Representation);
            }

            var groups = context.RiskFactorDimItemGroups.Include("RiskFactorDimItemGroupMembers");

            Console.WriteLine("\n\n*****Risk Factor Dim Item Groups*****");

            foreach (RiskFactorDimItemGroup group in groups)
            {
                Console.WriteLine(group.Representation);
                Console.WriteLine(" --- members --- ");

                foreach (RiskFactorDimItemGroupMember member in group.RiskFactorDimItemGroupMembers)
                {
                    Console.WriteLine(member.Representation);
                }
            }
        }
Пример #22
0
        private static void Test1()
        {
            try
            {

            using (var ScenGenContext = new ScenarioGeneratorModel("test user"))
            {

                Database.SetInitializer<ScenarioGeneratorModel>(new ScenarioGeneratorInitializer());

                ScenGenContext.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                var ScenarioGroups = ScenGenContext.ScenarioGroups.Where(a => (a.ApprovedAt != null));

                Console.WriteLine("*****Scenario Group List*****");
                foreach (ScenarioGroup group in ScenarioGroups)
                {
                        Console.Write("GROUP ID:" + group.ScenarioGroupID);

                    //var ScenarioDetails = group.ScenarioGroupDetails.GroupBy(a => a.ScenarioGroupID, (key, b) => b.OrderBy(c=>c.StartTime).First());
                    //foreach (ScenarioGroupDetail detail in ScenarioDetails)
                    //{
                    ScenarioGroupDetail detail = group.ScenarioGroupDetail;
                    Console.Write("  ::: " + detail.Name);
                    if (detail.ApprovedAt != null)
                        Console.WriteLine(" ::: Approved ");
                    else
                        Console.WriteLine(" ::: Unapproved ");

                    Console.WriteLine(" --- Children --- ");
                    foreach (ScenarioGroupDetail detail2 in group.ScenarioGroupChildrenDetails)
                    {
                        Console.Write(detail2.ScenarioGroupID);
                        Console.Write(" +++ " + detail2.Name);

                        if (detail2.ApprovedAt != null)
                            Console.WriteLine(" +++ Approved ");
                        else
                            Console.WriteLine(" +++ Unapproved ");
                    }

                }

                var Scenarios = ScenGenContext.Scenarios.Where(a => (a.ApprovedAt != null)).ToList();

                Console.WriteLine("*****Scenario List*****");
                foreach (Scenario scenario in Scenarios)
                {
                    Console.WriteLine(scenario.ScenarioID);
                    if (scenario.BaseScenario != null)
                        Console.WriteLine("derived from: " + scenario.BaseScenario.ScenarioID);
                    else
                        Console.WriteLine("original");

                    var ScenarioDetails = scenario.ScenarioDetails.Where(a => (a.ApprovedAt != null)).ToList();
                    foreach (ScenarioDetail detail in ScenarioDetails)
                    {
                        Console.Write(detail.Name);
                        Console.Write(" group: " + detail.ScenarioGroup.ScenarioDetails.First().Name);
                        if (detail.ApprovedAt != null)
                            Console.WriteLine(" Approved ");
                        else
                            Console.WriteLine(" Unapproved ");
                    }
                }

                }
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", validationErrors.Entry.Entity.GetType().Name, validationErrors.Entry.State);
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Console.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
            }

                //Console.WriteLine("*****Scenario List*****");
                //foreach (Scenario item in sc)
                //{
                //    Console.WriteLine(item.Name);
                //   //Console.WriteLine(item.ScenarioGroup.Name);
                //}

                // fetch specific scenarios
                // root.Familly("Macro").Display();
                // fetch all scenarios and sub groups
                //    root.Familly("Macro").Display();
                // fetch family and child scenario
                //root.Familly("Macro").ScenarioGroup("Adverse move on 1s3s tenor basis fly position").Display();
                //rep.GetScenarioGroups().Display();
                //rep.GetScenarios("Adverse move on 1s3s tenor basis fly position").Display();
                //root.Familly("Macro").ScenarioGroup("Adverse move on 1s3s tenor basis fly position").Scenario("ScenarioName").Display();

                //var list = root.Familly("Macro").ScenarioGroup("Adverse move on 1s3s tenor basis fly position").
                //   RiskFactor("IR Tenor Basis Spread")..ToList();
                //.RiskFactorDimension("Instrument Tenor")
                // .DisplayShock();

            Console.ReadKey();
        }
Пример #23
0
        static void Main(string[] args)
        {
            try
            {
                //using (var ScenGenContext = new ScenarioGeneratorModel("test user"))
                using (var ScenGenContext = new ScenarioGeneratorModel("test user", DateTime.Parse("2015-Sep-25")))
                //using (var ScenGenContext = new ScenarioGeneratorModel("test user", @"data source=FMD-D8-3076\TRIDENTD01;initial catalog=ScenarioV6;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework", DateTime.Parse("2015-Aug-13")))
                //using (var ScenGenContext = new ScenarioGeneratorModel("test user", @"data source=FMD-D8-3076\TRIDENTD01;initial catalog=ScenarioV6;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"))
                {
                    //Database.SetInitializer<ScenarioGeneratorModel>(new ScenarioGeneratorInitializer());
                    ScenGenContext.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                    Console.WriteLine("*****Scenario Group Details List*****");

                    var groupDetails = ScenGenContext.ScenarioGroupDetails;
                    foreach (ScenarioGroupDetail detail in groupDetails)
                    {
                        Console.WriteLine("  ::: " + detail.Representation);
                    }

                    ScenarioRepository ScenRep = new ScenarioRepository(ScenGenContext);

                    var list = ScenGenContext.ScenarioGroups.Where(sg => sg.ScenarioGroupDetails.OrderBy(c => c.StartTime).FirstOrDefault().ScenarioGroupParentID == null);

                    Console.WriteLine("*****Scenario Group List*****");

                    foreach (ScenarioGroup group in list)
                    {

                        Console.Write("GROUP ID:" + group.ScenarioGroupID);

                        ScenarioGroupDetail detail = group.ScenarioGroupDetail;
                        Console.Write("  ::: " + detail.Name);
                        if (detail.ApprovedAt != null)
                        {
                            Console.WriteLine(" ::: Approved ");
                            //detail.Name = detail.Name + "  CHANGED!!! ";
                        }
                        else
                        {
                            Console.WriteLine(" ::: Unapproved ");
                            //detail.ApprovedAt = DateTime.UtcNow;
                            //detail.ApprovedBy = "approver";
                        }

                        Console.WriteLine(" --- Children --- ");
                        foreach (ScenarioGroupDetail detail2 in group.ScenarioGroupChildrenDetails)
                        {
                            Console.Write(detail2.ScenarioGroupID);
                            Console.Write(" +++ " + detail2.Name);

                            if (detail2.ApprovedAt != null)
                            {
                                Console.WriteLine(" +++ Approved ");
                                detail2.Name = detail.Name + "  CHANGED!!! ";
                            }
                            else
                            {
                                Console.WriteLine(" +++ Unapproved ");
                                //detail2.ApprovedAt = DateTime.UtcNow;
                                //detail2.ApprovedBy = "approver";
                            }

                        }

                    }

                    //ScenarioGroup newGroup = new ScenarioGroup();
                    //ScenGenContext.Set<ScenarioGroup>().Add(newGroup);
                    //ScenarioGroupDetail newGroupDetail = new ScenarioGroupDetail() { Name = "New Group 2"};
                    //newGroup.ScenarioGroupDetails.Add(newGroupDetail);

                    ScenarioRepository Rep = new ScenarioRepository(ScenGenContext);
                    if (!ScenGenContext.ReadOnlyView)
                        Rep.SaveChanges3();

                }

            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", validationErrors.Entry.Entity.GetType().Name, validationErrors.Entry.State);
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Console.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
            }

            Console.ReadKey();
        }
Пример #24
0
        public void TestScenarioGroupDetailEditUnapproved()
        {
            ScenarioGroup main;
            ScenarioGroupDetail detail;

            int groupId = 2;
            int detailId;
            string name = "Scenario Group Detail Edit Unapproved Test";

            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                ScenarioGroupRepository repository = new ScenarioGroupRepository(context);

                main = repository.ScenarioGroups().Where(g => g.ScenarioGroupID == groupId).FirstOrDefault();
                detail = main.ScenarioGroupDetail;
                detailId = detail.ScenarioGroupDetailID;

                //make sure detail is not approved
                Assert.AreEqual(EntityStatus.Unapproved, detail.Status);

                //make sure main is approved
                Assert.AreEqual(EntityStatus.Approved, main.Status);

                detail.Name = name;
                repository.SaveChanges();

            }

            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                ScenarioGroupRepository repository = new ScenarioGroupRepository(context);

                main = repository.ScenarioGroups().Where(g => g.ScenarioGroupID == groupId).FirstOrDefault();
                detail = main.ScenarioGroupDetail;

                Assert.AreEqual(EntityStatus.Unapproved, detail.Status);
                Assert.AreEqual(detailId, detail.ScenarioGroupDetailID);
                Assert.AreEqual(context.UserName, detail.ModifiedBy);
                Assert.AreEqual(DateTime.MinValue, detail.StartTime);
                Assert.AreEqual(DateTime.MaxValue, detail.EndTime);
                Assert.AreEqual(true, detail.Latest);

                Assert.AreEqual(2, main.ScenarioGroupDetails.Count);
            }
        }
Пример #25
0
        public void TestScenarioGroupDetailApprovalWithUnapprovedGroup()
        {
            ScenarioGroup main;
            ScenarioGroupDetail detail;

            int groupId = 5;

            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                ScenarioGroupRepository repository = new ScenarioGroupRepository(context);

                main = repository.ScenarioGroups().Where(g => g.ScenarioGroupID == groupId).FirstOrDefault();
                detail = main.ScenarioGroupDetail;

                //make sure group is not approved
                Assert.AreEqual(EntityStatus.Unapproved, main.Status);
                //make sure detail is not approved
                Assert.AreEqual(EntityStatus.Unapproved, detail.Status);

                detail.Approve(context.UserName);
                Assert.AreEqual(EntityStatus.ApprovedInSession, detail.Status);
                repository.SaveChanges();

            }

            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                ScenarioGroupRepository repository = new ScenarioGroupRepository(context);

                main = repository.ScenarioGroups().Where(g => g.ScenarioGroupID == groupId).FirstOrDefault();
                detail = main.ScenarioGroupDetail;

                //main entity and details are approved now
                Assert.AreEqual(EntityStatus.Approved, main.Status);
                Assert.AreEqual(EntityStatus.Approved, detail.Status);

                Assert.AreEqual(context.UserName, main.ApprovedBy);
                Assert.AreEqual(context.UserName, detail.ApprovedBy);

                Assert.AreEqual(main.ApprovedAt, main.StartTime);
                Assert.AreEqual(detail.ApprovedAt, detail.StartTime);

                Assert.AreEqual(DateTime.MaxValue, main.EndTime);
                Assert.AreEqual(DateTime.MaxValue, detail.EndTime);

                //There should be only one (approved) detail
                Assert.AreEqual(1, main.ScenarioGroupDetails.Count);
            }
        }
Пример #26
0
        public void TestScenarioGroupChangeParentForUnapproved()
        {
            ScenarioGroup main;
            ScenarioGroupDetail detail;
            ScenarioGroup newParent;

            int groupId = 2;
            int parentId = 4;

            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                ScenarioGroupRepository repository = new ScenarioGroupRepository(context);

                main = repository.ScenarioGroups().Where(g => g.ScenarioGroupID == groupId).FirstOrDefault();
                detail = main.ScenarioGroupDetail;
                newParent = repository.ScenarioGroups().Where(g => g.ScenarioGroupID == parentId).FirstOrDefault();

                //make sure detail is not approved
                Assert.AreEqual(EntityStatus.Unapproved, detail.Status);

                Assert.AreEqual(true, repository.Move(detail, newParent));

                repository.SaveChanges();

            }

            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                ScenarioGroupRepository repository = new ScenarioGroupRepository(context);

                main = repository.ScenarioGroups().Where(g => g.ScenarioGroupID == groupId).FirstOrDefault();
                detail = main.ScenarioGroupDetail;

                Assert.AreEqual(EntityStatus.Unapproved, detail.Status);
                Assert.AreEqual(parentId, detail.ScenarioGroupParentID);
                Assert.AreEqual(context.UserName, detail.ModifiedBy);

            }
        }
Пример #27
0
        public void TestScenarioGroupChangeParentFailed()
        {
            int groupId = 1;
            int parentId = 4;
            ScenarioGroup item;
            ScenarioGroup newParent;

            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                ScenarioGroupRepository repository = new ScenarioGroupRepository(context);

                item = repository.ScenarioGroups().Where(g => g.ScenarioGroupID == groupId).FirstOrDefault();
                newParent = repository.ScenarioGroups().Where(g => g.ScenarioGroupID == parentId).FirstOrDefault();

                Assert.AreEqual(false, repository.Move(item.ScenarioGroupDetail, newParent));

                repository.SaveChanges();

                Assert.AreNotEqual(newParent.ScenarioGroupID, item.ScenarioGroupDetail.ScenarioGroupParentID);

            }
        }
Пример #28
0
        internal static void AddDimensions(ScenarioGeneratorModel context)
        {
            DateTime now = context.AsOfDate;

            var record = new RiskFactorDimension() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            var itemdimType = context.RiskFactorDimTypes.Where(x => x.Name == "Tenor").First();
            var item = new RiskFactorDimensionDetail() { Name = "Instrument Tenor", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            item.RiskFactorDimType = itemdimType;
            record.RiskFactorDimensionDetails.Add(item);
            context.RiskFactorDimensions.Add(record);

            record = new RiskFactorDimension() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            itemdimType = context.RiskFactorDimTypes.Where(x => x.Name == "Tenor").First();
            item = new RiskFactorDimensionDetail() { Name = "Underlying Tenor", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            item.RiskFactorDimType = itemdimType;
            record.RiskFactorDimensionDetails.Add(item);
            context.RiskFactorDimensions.Add(record);

            record = new RiskFactorDimension() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            itemdimType = context.RiskFactorDimTypes.Where(x => x.Name == "Country").First();
            item = new RiskFactorDimensionDetail() { Name = "Country of Risk", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            item.RiskFactorDimType = itemdimType;
            record.RiskFactorDimensionDetails.Add(item);
            context.RiskFactorDimensions.Add(record);

            record = new RiskFactorDimension() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            itemdimType = context.RiskFactorDimTypes.Where(x => x.Name == "Currency").First();
            item = new RiskFactorDimensionDetail() { Name = "Currency", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            item.RiskFactorDimType = itemdimType;
            record.RiskFactorDimensionDetails.Add(item);
            context.RiskFactorDimensions.Add(record);

            record = new RiskFactorDimension() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            itemdimType = context.RiskFactorDimTypes.Where(x => x.Name == "Currency").First();
            item = new RiskFactorDimensionDetail() { Name = "Underlying Currency", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            item.RiskFactorDimType = itemdimType;
            record.RiskFactorDimensionDetails.Add(item);
            context.RiskFactorDimensions.Add(record);

            record = new RiskFactorDimension() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            itemdimType = context.RiskFactorDimTypes.Where(x => x.Name == "Country").First();
            item = new RiskFactorDimensionDetail() { Name = "Country of Origin", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            item.RiskFactorDimType = itemdimType;
            record.RiskFactorDimensionDetails.Add(item);
            context.RiskFactorDimensions.Add(record);

            record = new RiskFactorDimension() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            itemdimType = context.RiskFactorDimTypes.Where(x => x.Name == "Region").First();
            item = new RiskFactorDimensionDetail() { Name = "Region of Risk", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            item.RiskFactorDimType = itemdimType;
            record.RiskFactorDimensionDetails.Add(item);
            context.RiskFactorDimensions.Add(record);

            record = new RiskFactorDimension() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            itemdimType = context.RiskFactorDimTypes.Where(x => x.Name == "Rating").First();
            item = new RiskFactorDimensionDetail() { Name = "Obligor Rating", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            item.RiskFactorDimType = itemdimType;
            record.RiskFactorDimensionDetails.Add(item);
            context.RiskFactorDimensions.Add(record);

            record = new RiskFactorDimension() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            itemdimType = context.RiskFactorDimTypes.Where(x => x.Name == "Sector").First();
            item = new RiskFactorDimensionDetail() { Name = "Instrument Sector", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            item.RiskFactorDimType = itemdimType;
            record.RiskFactorDimensionDetails.Add(item);
            context.RiskFactorDimensions.Add(record);

            record = new RiskFactorDimension() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            itemdimType = context.RiskFactorDimTypes.Where(x => x.Name == "Sector").First();
            item = new RiskFactorDimensionDetail() { Name = "Underlying Sector", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            item.RiskFactorDimType = itemdimType;
            record.RiskFactorDimensionDetails.Add(item);
            context.RiskFactorDimensions.Add(record);

            context.SaveChanges();
        }
Пример #29
0
        internal static void AddDimTypes(ScenarioGeneratorModel context)
        {
            DateTime now = context.AsOfDate;

            var item = new RiskFactorDimType() { Name = "Tenor", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-120), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", ModifiedAt = now.AddDays(-110), ModifiedBy = "C", Latest = true };
            context.RiskFactorDimTypes.Add(item);

            item = new RiskFactorDimType() { Name = "Rating", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-120), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", ModifiedAt = now.AddDays(-110), ModifiedBy = "C", Latest = true };
            context.RiskFactorDimTypes.Add(item);

            item = new RiskFactorDimType() { Name = "Seniority", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-120), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", ModifiedAt = now.AddDays(-110), ModifiedBy = "C", Latest = true };
            context.RiskFactorDimTypes.Add(item);

            item = new RiskFactorDimType() { Name = "Sector", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-120), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", ModifiedAt = now.AddDays(-110), ModifiedBy = "C", Latest = true };
            context.RiskFactorDimTypes.Add(item);

            item = new RiskFactorDimType() { Name = "Currency", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-120), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", ModifiedAt = now.AddDays(-110), ModifiedBy = "C", Latest = true };
            context.RiskFactorDimTypes.Add(item);

            item = new RiskFactorDimType() { Name = "IR Index", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-120), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", ModifiedAt = now.AddDays(-110), ModifiedBy = "C", Latest = true };
            context.RiskFactorDimTypes.Add(item);

            item = new RiskFactorDimType() { Name = "IL Index", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-120), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", ModifiedAt = now.AddDays(-110), ModifiedBy = "C", Latest = true };
            context.RiskFactorDimTypes.Add(item);

            item = new RiskFactorDimType() { Name = "CDS Index", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-120), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", ModifiedAt = now.AddDays(-110), ModifiedBy = "C", Latest = true };
            context.RiskFactorDimTypes.Add(item);

            item = new RiskFactorDimType() { Name = "Ticker", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-120), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", ModifiedAt = now.AddDays(-110), ModifiedBy = "C", Latest = true };
            context.RiskFactorDimTypes.Add(item);

            item = new RiskFactorDimType() { Name = "Country", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-120), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", ModifiedAt = now.AddDays(-110), ModifiedBy = "C", Latest = true };
            context.RiskFactorDimTypes.Add(item);

            item = new RiskFactorDimType() { Name = "Region", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now.AddDays(-120), CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", ModifiedAt = now.AddDays(-110), ModifiedBy = "C", Latest = true };
            context.RiskFactorDimTypes.Add(item);

            context.SaveChanges();
        }
Пример #30
0
        public void TestNewScenarioGroup()
        {
            ScenarioGroup parent;
            ScenarioGroup main;
            ScenarioGroupDetail detail;
            int parentId = 1;
            string name = "New Scenario Group Test";

            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                ScenarioGroupRepository repository = new ScenarioGroupRepository(context);

                parent = repository.ScenarioGroups().Where(p => p.ScenarioGroupID == parentId).FirstOrDefault();

                detail = repository.Add(parent);
                detail.Name = name;
                main = detail.ScenarioGroup;

                Assert.AreEqual(EntityStatus.UnapprovedInSession, detail.Status);
                Assert.AreEqual(EntityStatus.UnapprovedInSession, main.Status);
                Assert.AreEqual("Unapproved", detail.DisplayStatus);
                Assert.AreEqual("Unapproved", main.DisplayStatus);
                Assert.AreEqual(parent, detail.ScenarioGroupParent);

                repository.SaveChanges();
            }

            using (var context = new ScenarioGeneratorModel(UserName, Connection))
            {
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                ScenarioGroupRepository repository = new ScenarioGroupRepository(context);

                detail = repository.ScenarioGroupDetails().Where(d => d.Name == name).FirstOrDefault();

                Assert.AreEqual(EntityStatus.Unapproved, detail.Status);
                Assert.AreEqual(DateTime.MinValue, detail.StartTime);
                Assert.AreEqual(DateTime.MaxValue, detail.EndTime);
                Assert.AreEqual(context.UserName, detail.CreatedBy);

                parent = repository.ScenarioGroups().Where(p => p.ScenarioGroupID == parentId).FirstOrDefault();

                Assert.AreEqual(parent, detail.ScenarioGroupParent);

                main = detail.ScenarioGroup;

                Assert.AreEqual(EntityStatus.Unapproved, main.Status);
                Assert.AreEqual(DateTime.MinValue, main.StartTime);
                Assert.AreEqual(DateTime.MaxValue, main.EndTime);
                Assert.AreEqual(context.UserName, main.CreatedBy);

            }
        }