public void GetGridByEntityId_OnMultipleFound_ShouldThrow() { string TestEntityId = "testid"; XElement TestBlueprint = TestHelpers.DataBuilder.BuildBlueprint() .AndGridWith() .EntityId(TestEntityId) .ThatsAll() .AndGridWith() .EntityId(TestEntityId) .ThatsAll(); BlueprintDataContext DataContext = new BlueprintDataContext(TestBlueprint); Assert.That(TestBlueprint.Descendants("EntityId").Where(e => e.Value == TestEntityId).Count, Is.GreaterThan(1), "Test blueprint should contain more than one instance of the tested EntityId."); Assert.Multiple(() => { // assert that it throws internal exception var ex = Assert.Throws <AppException>( () => DataContext.GetGridByEntityId(TestEntityId), $"Tested method should throw {nameof(AppException)}."); // assert proper internal exception kind Assert.That(ex.ExceptionKind, Is.EqualTo(ExceptionKind.Blueprint_GridEntityIdNotUnique), $"Threw method should be of kind {nameof(ExceptionKind.Blueprint_GridEntityIdNotUnique)}."); }); }
public void GetGridByEntityId_OnSingleFound_ShouldReturnGrid() { string TestEntityId = "123456"; XElement TestBlueprint = TestHelpers.DataBuilder.BuildBlueprint() .AndGridWith() .EntityId(TestEntityId) .ExportThis(out XElement ExpectedResultGrid) // Note out ExpectedResultGrid .ThatsAll() .AndGridWith() .EntityId("arbitraryid") .ThatsAll(); BlueprintDataContext DataContext = new BlueprintDataContext(TestBlueprint); // Affirm preconditions Assert.That(TestBlueprint.Descendants("EntityId").Where(e => e.Value == TestEntityId).Count, Is.EqualTo(1), "Test blueprint should contain a single instance of the tested EntityId."); var res = DataContext.GetGridByEntityId(TestEntityId); Assert.That(res, Is.EqualTo(ExpectedResultGrid)); }
public void GetGridByEntityId_OnNotFound_ShouldReturnNull() { string TestEntityId = "testid"; // Test data not containing the tested entity ID XElement TestBlueprint = TestHelpers.DataBuilder.BuildBlueprint() .AndGridWith() .EntityId("SomethingSomethingInTheMonthOfMay") .ThatsAll() .AndGridWith() .EntityId("ArbitraryId") .ThatsAll(); BlueprintDataContext DataContext = new BlueprintDataContext(TestBlueprint); // Affirm preconditions Assert.That(TestBlueprint.Descendants("EntityId").Where(e => e.Value == TestEntityId).Count, Is.Zero, "Test blueprint shouldn't contain the tested EntityId."); var res = DataContext.GetGridByEntityId(TestEntityId); Assert.That(res, Is.Null, "Return value should be null when looking up non-existing entity ID."); }