コード例 #1
0
        public void TestPostAddProfession()
        {
            var newProfessions = new List <string> {
                "testProfOne", "testProfTwo"
            };
            var expected = new EmployeeModel()
            {
                Age         = _testEmployeeModel.Age,
                FirstName   = _testEmployeeModel.FirstName,
                LastName    = _testEmployeeModel.LastName,
                Professions = new List <ProfessionModel>(_testEmployeeModel.Professions)
            };

            newProfessions.ForEach(n => expected.Professions.Add(new ProfessionModel {
                ProfessionName = n
            }));

            var mock = new Mock <IEmployeeDbContext>();

            mock.Setup(x => x.FindModelById(It.Is <int>(id => id == 1)))
            .Returns(_testEmployeeModel);
            mock.Setup(x => x.SaveChanges());

            var controller   = new EmployeeController(mock.Object);
            var actionResult = controller.AddProfession(new NewProfessionsDto {
                Id = 1, ProfessionNames = newProfessions
            });
            var actual = actionResult as OkNegotiatedContentResult <EmployeeModel>;

            mock.Verify(x => x.FindModelById(It.IsAny <int>()));
            mock.Verify(x => x.SaveChanges());

            Assert.IsNotNull(actual);
            var compareLogic      = new CompareLogic(_config);
            var comparationResult = compareLogic.Compare(expected, actual.Content);

            Assert.IsTrue(comparationResult.AreEqual, comparationResult.DifferencesString);
        }