示例#1
0
        public GenericSystemsControllerTests()
        {
            var systemModel = new GenericSystemViewModel
            {
                Id          = "5a8417338317338c8e0809e5",
                Name        = "Ambulance Service Call Handler",
                FModule     = "Ambulance_Service_Call_Handler",
                Asid        = "200000000115",
                Context     = "Some context...",
                ActionTypes = new List <ActorType> {
                    ActorType.Consumer
                }
            };

            var personelModel = new PersonnelViewModel
            {
                Id       = "5a8417f68317338c8e080a62",
                Name     = "999 Call Handler",
                ImageUrl = "....",
                Context  = new List <ContentView>()
                {
                    new ContentView
                    {
                        Title   = "Title Text",
                        Content = new List <string> {
                            "Content Text"
                        },
                        CssClass = "CssClass Text",
                        Order    = 1
                    }
                },
                UsesNrls            = true,
                ActorOrganisationId = "5a82f9ffcb969daa58d33377",
                CModule             = "CModule-Type",
                SystemIds           = new List <string> {
                    "5a8417338317338c8e0809e5"
                },
                Benefits = new List <string> {
                    "benefitid"
                }
            };

            var genericSystemService = new Mock <IGenericSystemService>();

            genericSystemService.Setup(x => x.GetById(It.Is <string>(y => y == "5a8417338317338c8e0809e5"))).Returns(Task.Run(() => systemModel));
            genericSystemService.Setup(x => x.GetById(It.Is <string>(y => y == "5a8417338317338c8e0809e6"))).Returns(Task.Run(() => (GenericSystemViewModel)null));

            var personnelService = new Mock <IPersonnelService>();

            personnelService.Setup(x => x.GetModelBySystemId(It.Is <string>(y => y == "5a8417f68317338c8e080a62"))).Returns(Task.Run(() => personelModel));
            personnelService.Setup(x => x.GetModelBySystemId(It.Is <string>(y => y == "5a8417f68317338c8e080a63"))).Returns(Task.Run(() => (PersonnelViewModel)null));

            _genericSystemService = genericSystemService.Object;
            _personnelService     = personnelService.Object;
        }
        public static GenericSystemViewModel ToViewModel(GenericSystem model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model), "Cannot map null GenericSystem");
            }

            var viewModel = new GenericSystemViewModel
            {
                Id          = model.Id.ToString(),
                Context     = model.Context,
                Asid        = model.Asid,
                FModule     = model.FModule,
                ActionTypes = model.ActionTypes.Select(x => EnumHelpers.GetEnum <ActorType>(x)).ToList(),
                Name        = model.Name
            };

            return(viewModel);
        }
        public void GenericSystem_Returns_ValidViewModel()
        {
            var models = MongoGenericSystems.GenericSystems;

            var viewModel = models.Select(GenericSystem.ToViewModel).First();

            var expectedViewModel = new GenericSystemViewModel
            {
                Id          = "5a8417338317338c8e0809e5",
                Name        = "Ambulance Service Call Handler",
                FModule     = "Ambulance_Service_Call_Handler",
                Asid        = "200000000115",
                Context     = "Some context...",
                ActionTypes = new List <ActorType> {
                    ActorType.Consumer
                }
            };

            Assert.Equal(expectedViewModel, viewModel, Comparers.ModelComparer <GenericSystemViewModel>());
        }