public void CallByNameTest() { //expected Dog dog = new Dog("Вовкодав", "ч"); Dog dog1 = new Dog("Диктатор", "ч"); Dog dog2 = new Dog("Диктатор", "ч"); Room room = new Room(); room.Add(dog); room.Add(dog1); room.Add(dog2); RoomStub roomStub = new RoomStub(); room.room = roomStub; string expexted = "expexted"; List <string> expectedList = new List <string>() { "expectedList" }; Mock.Arrange(() => dog1.Voice()).Returns(expexted); Mock.Arrange(() => dog2.Voice()).Returns(expexted); Mock.Arrange(() => roomStub.Call(Arg.IsAny <string>())).Returns(expectedList); // actual List <string> list = room.Call("Диктатор"); Assert.AreEqual(expexted, list[0]); Assert.AreEqual(expexted, list[1]); Assert.AreEqual(expectedList[0], list[2]); Assert.AreEqual(3, list.Count); // Кімната для тестування виклику з вольєра. Room room1 = new Room(); Volary volary = new Volary(); room1.volary = volary; List <string> expectedVolary = new List <string>() { "expectedVolary" }; Mock.Arrange(() => volary.Call(Arg.IsAny <string>())).Returns(expectedVolary); List <string> actualList = room1.Call("AnyName"); Assert.AreEqual(expectedVolary[0], actualList[0]); }
public void CallTest() { //expected Room room = new Room(); room.BuildVolary(); RoomStub roomStub = new RoomStub(); room.room = roomStub; List <string> expectedVolary = new List <string> { "expectedVolary" }; List <string> expectedList = new List <string>() { "expectedList" }; Mock.Arrange(() => room.volary.Call()).Returns(expectedVolary); Mock.Arrange(() => roomStub.Call()).Returns(expectedList); // actual List <string> list = room.Call(); Assert.AreEqual(expectedList[0], list[0]); Assert.AreEqual(expectedVolary[0], list[1]); // Інша кімната без вольєрів. string expected = "expected"; Room room1 = new Room(); Dog dog = new Dog("Джекпот", "ч"); room1.Add(dog); Mock.Arrange(() => dog.Voice()).Returns(expected); List <string> list1 = room1.Call(); Assert.AreEqual(expected, list1[0]); }