public void Equals_EqualPaths_ShouldReturnTrue(params string[] parms) { // arrange var extraPath = new CodePath(); var sut1 = new CodePath(); foreach (var name in parms) { var mockedMethod = Mock.Create <Method>(); Mock.Arrange(() => mockedMethod.FullName).Returns(name); sut1.AddLast(mockedMethod); } var sut2 = new CodePath(); foreach (var name in parms) { var mockedMethod = Mock.Create <Method>(); Mock.Arrange(() => mockedMethod.FullName).Returns(name); sut2.AddLast(mockedMethod); } // act var actual = sut1.Equals(sut2); // assert Assert.Equal(parms.Length, sut1.Length); Assert.Equal(parms.Length, sut2.Length); Assert.True(actual); }
public void AddLast_AddMultiple_ShouldAddAllNodes(params string[] parms) { // arrange var sut = new CodePath(); var list = new List <Method>(); foreach (var name in parms) { var mockedMethod = Mock.Create <Method>(); Mock.Arrange(() => mockedMethod.FullName).Returns(name); list.Add(mockedMethod); } // act foreach (var method in list) { sut.AddLast(method); } Assert.Equal(parms.Length, sut.Count()); // assert foreach (var pair in sut.Zip(parms, (x, y) => new KeyValuePair <Method, String>(x, y))) { Assert.Equal(pair.Value, pair.Key.FullName); } }
public void ConcatNew_ShouldMaintainOldChain(params string[] parms) { // arrange var extraPath = new CodePath(); var sut = new CodePath(); foreach (var name in parms) { var mockedMethod = Mock.Create <Method>(); Mock.Arrange(() => mockedMethod.FullName).Returns(name); extraPath.AddLast(mockedMethod); sut.AddLast(mockedMethod); } // act sut.ConcatNew(extraPath); // assert var actualCount = sut.Count(); Assert.Equal(parms.Length, actualCount); Assert.Equal(parms.Length, sut.Length); var index = 0; foreach (var method in sut) { Assert.Equal(parms[index++], method.FullName); } }
public void ConcatNew_ConcatPartial_ShouldConcatFullChain(params string[][] parms) { // arrange var extraPath = new CodePath(); var sut = new CodePath(); foreach (var name in parms[0]) { var mockedMethod = Mock.Create <Method>(); Mock.Arrange(() => mockedMethod.FullName).Returns(name); sut.AddLast(mockedMethod); } foreach (var name in parms[1]) { var mockedMethod = Mock.Create <Method>(); Mock.Arrange(() => mockedMethod.FullName).Returns(name); extraPath.AddLast(mockedMethod); } // form expected final path var expected = parms[0].Concat(parms[1].Skip(2)); // act var newSut = sut.ConcatNew(extraPath.GetSubPaths().ToList()[1]); // assert Assert.Equal(parms[0].Length + parms[1].Length - 2, newSut.Count()); Assert.Equal(parms[0].Length + parms[1].Length - 2, newSut.Length); Assert.Equal(expected, newSut.Select(x => x.FullName)); }
public CodePath ToCodePath() { var path = new CodePath(); var idList = this.Ids.Split(','); foreach (var id in idList) { path.AddLast(new MockMethod(int.Parse(id))); } return(path); }
public void GetSubPaths_SubPathsHaveValidProperties(params string[] parms) { // arrange var sut = new CodePath(); foreach (var name in parms) { var mockedMethod = Mock.Create <Method>(); Mock.Arrange(() => mockedMethod.FullName).Returns(name); sut.AddLast(mockedMethod); } // act var subPathsList = sut.GetSubPaths().ToList(); // assert for (int i = 0; i < subPathsList.Count; i++) { var currentPath = subPathsList[i]; Assert.Equal(sut.Length - i - 1, currentPath.Length); Assert.Equal(sut.ElementAt(i + 1), currentPath.FirstMethod); Assert.Equal(sut.LastMethod, currentPath.LastMethod); } }
public void AddLast_AddMultiple_ShouldHaveProperLength(params string[] parms) { // arrange var sut = new CodePath(); var list = new List <Method>(); foreach (var name in parms) { var mockedMethod = Mock.Create <Method>(); Mock.Arrange(() => mockedMethod.FullName).Returns(name); list.Add(mockedMethod); } // act foreach (var method in list) { sut.AddLast(method); } Assert.Equal(parms.Length, sut.Count()); // assert Assert.Equal(parms.Length, sut.Length); }