public void GetByUserIdShouldReturnAreaWhenAvailable()
        {
            var areasListCollection = new Area[]
            {
                new Area {Id = 0 },
                new Area {Id = 1 },
                new Area {Id = 2 },
            };

            int y = 0;
            var areasRepositoryFake = new Mock<IRepository<Area>>();
            areasRepositoryFake
                .Setup<Area>(x => x.GetById(It.IsAny<int>()))
                .Returns(() => areasListCollection.FirstOrDefault(a => a.Id == y));

            var dataFake = new Mock<IQmsData>();
            dataFake.Setup(x => x.Areas).Returns(areasRepositoryFake.Object);
            var service = new AreasServices(dataFake.Object);

            for (int i = 0; i < areasListCollection.Count(); i++)
            {
                y = i;
                var areaSelected = service.GetById(i);
                Assert.AreEqual(i, areaSelected.Id);
            }
        }
예제 #2
0
        public int Add(string name, string description, int departmentId, string employeeId)
        {
            var areaToAdd = new Area
            {
                Name = name,
                Description = description,
                DepartmentId = departmentId,
                EmployeeId = employeeId
            };

            this.data.Areas.Add(areaToAdd);
            this.data.SaveChanges();
            return areaToAdd.Id;
        }
        public void UpdateShouldWorkProperly()
        {
            var areasListCollection = new Area[]
            {
                new Area {Id = 0 },
                new Area {Id = 1 },
                new Area {Id = 2 },
            };

            int y = 1;
            var areasRepositoryFake = new Mock<IRepository<Area>>();
            areasRepositoryFake
                .Setup<Area>(x => x.GetById(It.IsAny<int>()))
                .Returns(() => areasListCollection.FirstOrDefault(a => a.Id == y));

            var dataFake = new Mock<IQmsData>();
            dataFake.Setup(x => x.Areas).Returns(areasRepositoryFake.Object);
            var service = new AreasServices(dataFake.Object);

            service.Update(y, "name", "description", "employId");
            var updatedArea = service.GetById(y);

            Assert.AreEqual("name", updatedArea.Name);
            Assert.AreEqual("description", updatedArea.Description);
            Assert.AreEqual("employId", updatedArea.EmployeeId);
        }