public void ComponentTypeService_GetAsync_ReturnsComponentTypesByIds()
        {
            //Arrange
            var mockDbContextScopeFac = new Mock<IDbContextScopeFactory>();
            var mockDbContextScope = new Mock<IDbContextReadOnlyScope>();
            var mockEfDbContext = new Mock<EFDbContext>();
            mockDbContextScopeFac.Setup(x => x.CreateReadOnly(DbContextScopeOption.JoinExisting)).Returns(mockDbContextScope.Object);
            mockDbContextScope.Setup(x => x.DbContexts.Get<EFDbContext>()).Returns(mockEfDbContext.Object);

            var dbEntry1 = new ComponentType { Id = "dummyEntryId1", CompTypeName = "Name1", CompTypeAltName = "NameAlt1", IsActive_bl = false };
            var dbEntry2 = new ComponentType { Id = "dummyEntryId2", CompTypeName = "Name2", CompTypeAltName = "NameAlt2", IsActive_bl = true };
            var dbEntry3 = new ComponentType { Id = "dummyEntryId3", CompTypeName = "Name3", CompTypeAltName = "NameAlt3", IsActive_bl = true };
            var dbEntries = (new List<ComponentType> { dbEntry1, dbEntry2, dbEntry3 }).AsQueryable();

            var mockDbSet = new Mock<DbSet<ComponentType>>();
            mockDbSet.As<IDbAsyncEnumerable<ComponentType>>().Setup(m => m.GetAsyncEnumerator()).Returns(new MockDbAsyncEnumerator<ComponentType>(dbEntries.GetEnumerator()));
            mockDbSet.As<IQueryable<ComponentType>>().Setup(m => m.Provider).Returns(new MockDbAsyncQueryProvider<ComponentType>(dbEntries.Provider));
            mockDbSet.As<IQueryable<ComponentType>>().Setup(m => m.Expression).Returns(dbEntries.Expression);
            mockDbSet.As<IQueryable<ComponentType>>().Setup(m => m.ElementType).Returns(dbEntries.ElementType);
            mockDbSet.As<IQueryable<ComponentType>>().Setup(m => m.GetEnumerator()).Returns(dbEntries.GetEnumerator());
            mockDbSet.Setup(x => x.Include(It.IsAny<string>())).Returns(mockDbSet.Object);

            mockEfDbContext.Setup(x => x.ComponentTypes).Returns(mockDbSet.Object);

            var compTypeService = new ComponentTypeService(mockDbContextScopeFac.Object, "dummyUserId");

            //Act
            var serviceResult = compTypeService.GetAsync(new string[] { "dummyEntryId3" }).Result;

            //Assert
            Assert.IsTrue(serviceResult.Count == 1);
            Assert.IsTrue(serviceResult[0].CompTypeAltName.Contains("NameAlt3"));

        }
示例#2
0
        public ActionResult Index(int?page)
        {
            int pageNumber = (page ?? 1);

            IEnumerable <ComponentTypeDTO> componentTypeDTOs = ComponentTypeService.GetListOrderedByName().ToList();
            IEnumerable <ComponentTypeVM>  componentTypeVMs  = Mapper.Map <IEnumerable <ComponentTypeVM> >(componentTypeDTOs);

            return(View(componentTypeVMs.ToPagedList(pageNumber, PageSize)));
        }
示例#3
0
        public ActionResult Create([Bind(Include = "Name")] ComponentTypeVM componentTypeVM)
        {
            if (ModelState.IsValid)
            {
                ComponentTypeDTO componentTypeDTO = Mapper.Map <ComponentTypeDTO>(componentTypeVM);
                ComponentTypeService.Add(componentTypeDTO);

                return(RedirectToAction("Index"));
            }

            return(View());
        }
示例#4
0
        public ActionResult Delete(Guid id)
        {
            try
            {
                ComponentTypeService.Delete(id);
            }
            catch (NotFoundException)
            {
                return(HttpNotFound());
            }
            catch (HasRelationsException)
            {
                return(Content("Удаление невозможно."));
            }

            return(RedirectToAction("Index"));
        }
示例#5
0
        public ActionResult Edit(Guid?id)
        {
            try
            {
                ComponentTypeDTO componentTypeDTO = ComponentTypeService.Get(id);
                ComponentTypeVM  componentTypeVM  = Mapper.Map <ComponentTypeVM>(componentTypeDTO);

                return(View(componentTypeVM));
            }
            catch (ArgumentNullException)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadGateway));
            }
            catch (NotFoundException)
            {
                return(HttpNotFound());
            }
        }
        protected DispatcherContext(string configDbConnectionString = null)
        {
            _dbContext = new DatabasesContext
            {
                IsInternalDispatcherContext = true,
                ConfigDbConnectionString    = configDbConnectionString
            };

            EventService             = new EventService(this);
            EventTypeService         = new EventTypeService(this);
            BulbService              = new BulbService(this);
            ComponentTypeService     = new ComponentTypeService(this);
            LogService               = new LogService(this);
            MetricService            = new MetricService(this);
            UnitTestTypeService      = new UnitTestTypeService(this);
            UnitTestService          = new UnitTestService(this);
            SubscriptionService      = new SubscriptionService(DbContext);
            PaymentService           = ConfigDbServicesHelper.GetPaymentService(DbContext);
            ComponentService         = new ComponentService(this);
            UserService              = new UserService(DbContext);
            AccountService           = ConfigDbServicesHelper.GetAccountService();
            AccountManagementService = ConfigDbServicesHelper.GetAccountManagementService(this);
            DatabaseService          = ConfigDbServicesHelper.GetDatabaseService();
        }
 //Constructors---------------------------------------------------------------------------------------------------------//
 public ComponentTypeSrvController(ComponentTypeService compTypeService)
 {
     this.compTypeService = compTypeService;
 }