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); } }
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); } }
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); } }
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); } }
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); } }