public void Can_use_Composite() { // Arrange var sut = new FakeSut(); var rootStartingAt5 = new TestRoot<DummyItem>("Starting with IntProperty = 5", () => new DummyItem(5)); rootStartingAt5.Add(new TestLeaf<DummyItem>(rootStartingAt5, new Mutation<DummyItem>("setting it to 4", d => { d.IntProperty = 4; }))); rootStartingAt5.Add(new TestLeaf<DummyItem>(rootStartingAt5, new Mutation<DummyItem>("setting it to 3", d => { d.IntProperty = 3; }))); var adding2 = new TestComposite<DummyItem>(rootStartingAt5, new Mutation<DummyItem>("adding 2", d => { d.IntProperty = d.IntProperty + 2; })); adding2.Add(new TestLeaf<DummyItem>(adding2, new Mutation<DummyItem>("removing 1", d => { d.IntProperty = d.IntProperty - 1; }))); adding2.Add(new TestLeaf<DummyItem>(adding2, new Mutation<DummyItem>("removing 3", d => { d.IntProperty = d.IntProperty - 3; }))); rootStartingAt5.Add(adding2); var adding3 = new TestComposite<DummyItem>(rootStartingAt5, new Mutation<DummyItem>( "adding 3", d => { d.IntProperty = d.IntProperty + 3; })); adding2.Add(new TestLeaf<DummyItem>(adding3, new Mutation<DummyItem>("removing 2", d => { d.IntProperty = d.IntProperty - 2; }))); adding2.Add(new TestLeaf<DummyItem>(adding3, new Mutation<DummyItem>("removing 4", d => { d.IntProperty = d.IntProperty - 4; }))); rootStartingAt5.Add(adding3); //Assert.AreEqual("", String.Join("\n", rootStartingAt5.Enumerate().ToList().Select(t => t.Description))); rootStartingAt5.Walk((start) => { var initial = start.Arrange(); var actual = sut.DoIt(initial); DummyAssert.AssertIsNotFive(actual, start.Description); }); // Act // Assert }
void IDL.updateTest(int testNumber, Test updatedTest) { XElement testElement = (from testItem in TestRoot.Elements() where int.Parse(testItem.Element("TestNumber").Value) == testNumber select testItem).FirstOrDefault(); if (testElement == null) { throw new TestNumberNotFoundException(testNumber); } testElement.Remove(); TestRoot.Add(updatedTest.ToXmlTest()); TestRoot.Save(TestPath); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int IDL.addTest(Test testToAdd) { //to do: make a running code for tests int testCode = int.Parse(ConfigRoot.Element("BeginningSerialTestNumber").Element("Value").Value); int testNumber = (from test in TestRoot.Elements() where (int.Parse(test.Element("TestNumber").Value) == testToAdd.TestNumber) select(int.Parse(test.Element("TestNumber").Value))).FirstOrDefault(); if (testNumber != 0) { throw new TestNumberAlreadyExistsException(testNumber); } testToAdd.TestNumber = testCode; TestRoot.Add(testToAdd.ToXmlTest()); TestRoot.Save(TestPath); ConfigRoot.Element("BeginningSerialTestNumber").Element("Value").Value = (testCode + 1).ToString(); ConfigRoot.Save(ConfigPath); return(testCode); }