Exemple #1
0
        public void PutContact_ShouldReturnOk()
        {
            var contactsTestData = new List <EmployeeContact>()
            {
                new EmployeeContact {
                    Id = 1, EmployeeId = 2
                },
                new EmployeeContact {
                    Id = 2, Deleted = true, EmployeeId = 2
                },
                new EmployeeContact {
                    Id = 3, EmployeeId = 3
                }
            };
            var contacts  = MockHelper.MockDbSet(contactsTestData);
            var dbContext = new Mock <IAppDbContext>();

            dbContext.Setup(m => m.EmployeeContacts).Returns(contacts.Object);
            dbContext.Setup(d => d.Set <EmployeeContact>()).Returns(contacts.Object);
            var factory = new Mock <IDbContextFactory>();

            factory.Setup(m => m.CreateDbContext()).Returns(dbContext.Object);

            IDbContextFactory fac      = factory.Object;
            var             controller = new GTIWebAPI.Controllers.EmployeeContactsController(fac);
            EmployeeContact contact    = new EmployeeContact {
                Id = 3, EmployeeId = 25
            };
            var result = controller.PutEmployeeContact(3, contact.ToDTO()) as OkNegotiatedContentResult <EmployeeContactDTO>;

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Content.Id);
        }
Exemple #2
0
        public void GetContactsByEmployeeId_ShouldReturnZeroCount()
        {
            var contactsTestData = new List <EmployeeContact>()
            {
                new EmployeeContact {
                    Id = 1, EmployeeId = 2
                },
                new EmployeeContact {
                    Id = 2, Deleted = true, EmployeeId = 2
                },
                new EmployeeContact {
                    Id = 3, EmployeeId = 3
                }
            };
            var contacts  = MockHelper.MockDbSet(contactsTestData);
            var dbContext = new Mock <IAppDbContext>();

            dbContext.Setup(m => m.EmployeeContacts).Returns(contacts.Object);
            dbContext.Setup(d => d.Set <EmployeeContact>()).Returns(contacts.Object);
            var factory = new Mock <IDbContextFactory>();

            factory.Setup(m => m.CreateDbContext()).Returns(dbContext.Object);
            IDbContextFactory fac = factory.Object;
            var controller        = new GTIWebAPI.Controllers.EmployeeContactsController(fac);
            var badResult         = controller.GetEmployeeContactByEmployee(4) as OkNegotiatedContentResult <IEnumerable <EmployeeContactDTO> >;

            Assert.AreEqual(0, badResult.Content.Count());
        }
Exemple #3
0
        public void GetContactById_ShouldReturnNotFoundWhenIdIsNotFound()
        {
            var contactsTestData = new List <EmployeeContact>()
            {
                new EmployeeContact {
                    Id = 1, EmployeeId = 2
                },
                new EmployeeContact {
                    Id = 2, Deleted = true, EmployeeId = 2
                },
                new EmployeeContact {
                    Id = 3, EmployeeId = 3
                }
            };
            var contacts = MockHelper.MockDbSet(contactsTestData);

            contacts.Setup(d => d.Find(It.IsAny <object>())).Returns <object[]>((keyValues) => { return(contacts.Object.SingleOrDefault(product => product.Id == (int)keyValues.Single())); });

            var dbContext = new Mock <IAppDbContext>();

            dbContext.Setup(m => m.EmployeeContacts).Returns(contacts.Object);
            dbContext.Setup(d => d.Set <EmployeeContact>()).Returns(contacts.Object);
            var factory = new Mock <IDbContextFactory>();

            factory.Setup(m => m.CreateDbContext()).Returns(dbContext.Object);
            IDbContextFactory fac = factory.Object;
            var controller        = new GTIWebAPI.Controllers.EmployeeContactsController(fac);
            var badResult         = controller.GetEmployeeContact(999);

            Assert.IsInstanceOfType(badResult, typeof(NotFoundResult));
        }