Пример #1
0
        public void AddPhoneReturnsPersonPhone()
        {
            //Arrange
            moq.Setup(m => m.Get(It.IsAny <object[]>())).Returns <object[]>(id => Task.FromResult(new Person
            {
                Id     = (long)id[0],
                Phones = new List <PersonPhone>()
            }));
            moq.Setup(m => m.Put(It.IsAny <Person>())).Returns <Person>(p => Task.FromResult(p));
            long personId = 1;
            long phoneId  = personId + 1;

            //Act
            var result = (controller.AddPhone(new PersonPhone {
                PersonId = personId, PhoneId = phoneId
            }).Result
                          as OkObjectResult)?.Value;

            //Assert
            Assert.IsInstanceOfType(result, typeof(PersonPhone));
            Assert.AreEqual(personId, (result as PersonPhone)?.PersonId);
            Assert.AreEqual(phoneId, (result as PersonPhone)?.PhoneId);
        }