public MagicWiringDependencyFactory(Type type_being_created, DependencyContainer container,
                                     ConstructorSelectionStrategy strategy)
 {
     this.type_being_created = type_being_created;
     this.container = container;
     this.strategy = strategy;
 }
 public AutomaticDependencyFactory(ConstructorSelection constructor_selection, Type type_to_create,
                                   DependencyContainer dependency_container)
 {
     this.constructor_selection = constructor_selection;
     this.dependency_container = dependency_container;
     this.type_to_create = type_to_create;
 }
 public void it_should_return_the_dependency_created_by_the_factory_for_that_dependency()
 {
     the_factory_that_can_create_the_dependency.Stub(x => x.create()).Return(the_connection);
     dependency_container = new DependencyContainer(factories, error_handler);
     result = dependency_container.a<IDbConnection>();
     Assert.AreEqual(result, the_connection);
 }
 public AutomaticDependencyFactory(DependencyContainer dependency_container,
                                   ConstructorSelectionStrategy constructor_selection_strategy, Type type)
 {
     this.dependency_container = dependency_container;
     this.constructor_selection_strategy = constructor_selection_strategy;
     this.type = type;
 }
    public void run()
    {
      var the_container =
        new DependencyContainer(
          new DependencyFactories(startup_service, StartupItems.exceptions.missing_dependency_factory),
          StartupItems.exceptions.item_creation_error);

      ContainerFacadeResolution container_resolution = () => the_container;
      Container.facade_resolution = container_resolution;
      startup_service.register_instance(startup_service);
      startup_service.register_instance<IFetchDependencies>(the_container);
    }
        public void when_the_factory_that_creates_the_dependency_throws_a_dependency_creation_exception()
        {
            third_party_exception = new Exception();
            wrapped_exception = new Exception();

            error_handler = ((type, original_exception) =>
                {
                    Assert.AreEqual(type, typeof (IDbConnection));
                    Assert.AreEqual(original_exception, third_party_exception);
                    throw wrapped_exception;
                });

            the_factory_that_can_create_the_dependency.Stub(x => x.create()).Throw(third_party_exception);

            dependency_container = new DependencyContainer(factories, error_handler);
            dependency_container.a(typeof (IDbConnection));
        }
Пример #7
0
        public void WithString_ResolveType(string name, bool expected)
        {
            var container = new DependencyContainer();

            Assert.AreEqual(expected, container.TryResolve(name, out Human _));
        }
Пример #8
0
        public void WithoutRegister_FailResolveType()
        {
            var container = new DependencyContainer();

            Assert.IsFalse(container.TryResolve(out IAnimal instance));
        }
Пример #9
0
        public void WithTypeAndString_ResolveType(Type resolveType, string name, bool expected)
        {
            var container = new DependencyContainer();

            Assert.AreEqual(expected, container.TryResolve(resolveType, name, out _));
        }
Пример #10
0
 private void RegisterServices(IServiceCollection services)
 {
     DependencyContainer.RegisterServices(services);
 }
Пример #11
0
 protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) =>
 dependencies = new DependencyContainer(base.CreateLocalDependencies(parent));
Пример #12
0
 public static void RegisterServices(IServiceCollection services)
 {
     DependencyContainer.RegisterServices(services);
 }
Пример #13
0
 private static bool TryGetContainer(string slot, out DependencyContainer container)
 {
     return(Containers.TryGetValue(slot, out container));
 }
Пример #14
0
        public void WithType_ResolveContainer(Type resolveType)
        {
            var container = new DependencyContainer();

            Assert.IsTrue(container.CanResolve(resolveType));
        }
Пример #15
0
        public void ConsoleApplicationModuleWithXrmConnectionGenerateBatAndExecuteTest()
        {
            //this is done in the load.edit saved request form
            //a button is added the the saved request grid whiuch generates the .bat

            //so we need to save a request
            //then navigate to the save requests and trigger the generate bat button

            var testApplication = CreateThisApp();

            //set to no previously saved ones
            var savedRequests   = new SavedSettings();
            var settingsManager = testApplication.Controller.ResolveType <ISettingsManager>();

            settingsManager.SaveSettingsObject(savedRequests, typeof(TestSavedRequestWithXrmConnectionDialogRequest));

            //navigate to the request and populate the string field
            var entryForm = testApplication.NavigateToDialogModuleEntryForm <TestSavedRequestWithXrmConnectionModule, TestSavedRequestWithXrmConnectionDialog>();
            var request   = new TestSavedRequestWithXrmConnectionDialogRequest()
            {
                SomeArbitraryString = nameof(TestSavedRequestWithXrmConnectionDialogRequest.SomeArbitraryString)
            };

            testApplication.EnterObject(request, entryForm);

            //trigger save request
            var saveRequestButton = entryForm.GetButton("SAVEREQUEST");

            saveRequestButton.Invoke();

            //enter and save details including autoload
            var saveRequestForm = testApplication.GetSubObjectEntryViewModel(entryForm);
            var detailsEntered  = new SaveAndLoadFields()
            {
                Name = "TestName"
            };

            testApplication.EnterAndSaveObject(detailsEntered, saveRequestForm);
            Assert.IsFalse(entryForm.ChildForms.Any());
            Assert.IsFalse(entryForm.LoadingViewModel.IsLoading);

            //reopen app/dialog
            testApplication = CreateThisApp();
            entryForm       = testApplication.NavigateToDialogModuleEntryForm <TestSavedRequestWithXrmConnectionModule, TestSavedRequestWithXrmConnectionDialog>();

            //invoke load request dialog
            var loadRequestButton = entryForm.GetButton("LOADREQUEST");

            loadRequestButton.Invoke();
            var loadRequestForm = testApplication.GetSubObjectEntryViewModel(entryForm);

            //verify there is a saved request and trigger the generate bat button
            var subGrid = loadRequestForm.GetEnumerableFieldViewModel(nameof(SavedSettings.SavedRequests));

            Assert.IsTrue(subGrid.GridRecords.Count() == 1);
            subGrid.GridRecords.First().IsSelected = true;

            var generateBatButton = subGrid.DynamicGridViewModel.GetButton("GENERATEBAT");

            generateBatButton.Invoke();

            var testFiles = FileUtility.GetFiles(TestingFolder);

            Assert.AreEqual(1, testFiles.Count());
            Assert.IsTrue(testFiles.First().EndsWith(".bat"));

            var batContent = File.ReadAllText(testFiles.First());

            var args = ConsoleTestUtility.CommandLineToArgs(batContent)
                       .Skip(1)
                       .ToArray();

            var arguments       = ConsoleApplication.ParseCommandLineArguments(args);
            var applicationName = arguments.ContainsKey("SettingsFolderName") ? arguments["SettingsFolderName"] : "Unknown Console Context";

            //okay need to create app
            var dependencyResolver = new DependencyContainer();
            var controller         = new ConsoleApplicationController(applicationName, dependencyResolver);

            settingsManager = new DesktopSettingsManager(controller);
            var applicationOptions = new ApplicationOptionsViewModel(controller);
            var app = new ConsoleApplication(controller, applicationOptions, settingsManager);

            //load modules in folder path
            app.LoadModulesInExecutionFolder();

            //for this we will register saved connections in the console
            //in reality they would have been created on disk by the app and loaded by the module\

            //this was just debugging an invalid connection
            //var c1 = GetXrmRecordConfiguration();
            //var c2 = GetSavedXrmRecordConfiguration();
            //c1.Password = new Password("Nope", false, true);
            //c2.Password = new Password("Nope", false, true);
            //XrmConnectionModule.RefreshXrmServices(c1, app.Controller);
            //app.Controller.RegisterInstance<ISavedXrmConnections>(new SavedXrmConnections
            //{
            //    Connections = new[] { c2 }
            //});

            SavedXrmConnectionsModule.RefreshXrmServices(GetXrmRecordConfiguration(), app.Controller);
            app.Controller.RegisterInstance <ISavedXrmConnections>(new SavedXrmConnections
            {
                Connections = new[] { GetSavedXrmRecordConfiguration() }
            });

            //run app
            app.Run(args);
        }
Пример #16
0
        public void WithController_RegisterController()
        {
            var container = new DependencyContainer();

            Assert.IsNotNull(container.Register <Controller>());
        }
Пример #17
0
        public void WithoutRegister_FailResolveContainer()
        {
            var container = new DependencyContainer();

            Assert.IsFalse(container.CanResolve <Shark>(new Shark().Name));
        }
Пример #18
0
        public void WithResolveOptionsAndString_ResolveType(string name, bool expected)
        {
            var container = new DependencyContainer();

            Assert.AreEqual(expected, container.TryResolve(name, DependencyContainerResolveOptions.Default, out Shark _));
        }
Пример #19
0
        public void WithValidTypeAndResolveOptions_ResolveType()
        {
            var container = new DependencyContainer();

            Assert.IsTrue(container.TryResolve(DependencyContainerResolveOptions.Default, out Fish _));
        }
Пример #20
0
        public void WithInvalidTypeAndResolveOptions_FailResolveType()
        {
            var container = new DependencyContainer();

            Assert.IsFalse(container.TryResolve(DependencyContainerResolveOptions.Default, out IAnimal _));
        }
        private bool Test_Get_SummaryId(Guid summaryId)
        {
            using (var ioc = DependencyContainer.Resolve <IIncidentSummaryQueryService>())
            {
                var svc     = ioc.Instance;
                var summary = ioc.Instance.FindIncidentSummary(summaryId);


                var ids = summary.Others.Select(x => svc.FindIncidentPersonOtherSummaryId(x.Id));
                if (ids.Any(x => x != summaryId))
                {
                    return(false);
                }

                ids = summary.Victims.Select(x => svc.FindIncidentPersonVictimSummaryId(x.Id));
                if (ids.Any(x => x != summaryId))
                {
                    return(false);
                }

                ids = summary.Suspects.Select(x => svc.FindIncidentPersonSuspectSummaryId(x.Id));
                if (ids.Any(x => x != summaryId))
                {
                    return(false);
                }

                ids = summary.Drugs.Select(x => svc.FindIncidentDrugSummaryId(x.Id));
                if (ids.Any(x => x != summaryId))
                {
                    return(false);
                }

                ids = summary.Vehicles.Select(x => svc.FindIncidentVehicleSummaryId(x.Id));
                if (ids.Any(x => x != summaryId))
                {
                    return(false);
                }

                ids = summary.Property.Select(x => svc.FindIncidentPropertySummaryId(x.Id));
                if (ids.Any(x => x != summaryId))
                {
                    return(false);
                }

                ids = summary.Narratives.Select(x => svc.FindIncidentNarrativeSummaryId(x.Id));
                if (ids.Any(x => x != summaryId))
                {
                    return(false);
                }

                ids = summary.Officers.Select(x => svc.FindIncidentOfficerSummaryId(x.Id));
                if (ids.Any(x => x != summaryId))
                {
                    return(false);
                }

                ids = summary.Offenses.Select(x => svc.FindIncidentOffenseSummaryId(x.Id));
                if (ids.Any(x => x != summaryId))
                {
                    return(false);
                }

                ids = summary.IncidentOrganizations.Select(x => svc.FindIncidentOrganizationSummaryId(x.Id));
                if (ids.Any(x => x != summaryId))
                {
                    return(false);
                }

                ids = summary.OfficerInvolvedShootings.Select(x => svc.FindIncidentOfficerInvolvedShootingSummaryId(x.Id));
                if (ids.Any(x => x != summaryId))
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #22
0
#pragma warning restore CS0169

        static RedisConnectionHelper()
        {
            connectionMultiplexer = DependencyContainer.GetService <IConnectionMultiplexer>() ?? throw new ArgumentNullException(nameof(IConnectionMultiplexer));
        }
Пример #23
0
        private Guid TestCaseWithAssociations()
        {
            var  agencyId = GetAgencies()[0].AgencyId;
            Guid caseId;

            using (var caseCmdSvc = DependencyContainer.Resolve <ICaseCommandService>())
                using (var incidentCmdSvc = DependencyContainer.Resolve <IIncidentSummaryCommandService>())
                    using (var incidentQuerySvc = DependencyContainer.Resolve <IIncidentSummaryQueryService>())
                        using (var arrestCmdSvc = DependencyContainer.Resolve <IArrestSummaryCommandService>())
                            using (var fieldInterviewCmdSvc = DependencyContainer.Resolve <IFieldInterviewSummaryCommandService>())
                                using (var mediaSvc = DependencyContainer.Resolve <IMediaMetaService>())
                                    using (var mediaDataCmdSvc = DependencyContainer.Resolve <IMediaDataService>())
                                    {
                                        // Create a Case.
                                        string caseNumber = new Random().Next(int.MaxValue).ToString();
                                        caseId = caseCmdSvc.Instance.CreateCase(agencyId, caseNumber, DTOFactory.NewCaseDetails);

                                        // Create media.
                                        Guid mediaId = mediaSvc.Instance.CreateNewMedia(DTOFactory.NewMedia);
                                        mediaDataCmdSvc.Instance.UploadMediaData(new Application.Contracts.Media.DTO.MediaData()
                                        {
                                            Id = mediaId, Data = DTOFactory.NewMediaData
                                        });

                                        //
                                        // Create an associated Incident.
                                        //
                                        Guid incidentId = incidentCmdSvc.Instance.CreateIncidentSummary(agencyId, caseId, DTOFactory.NewIncidentSummary);
                                        incidentCmdSvc.Instance.CreateIncidentDrug(incidentId, DTOFactory.NewIncidentDrug);
                                        incidentCmdSvc.Instance.CreateIncidentEvent(incidentId, DTOFactory.NewIncidentEvent);
                                        incidentCmdSvc.Instance.CreateIncidentGun(incidentId, DTOFactory.NewIncidentGun);

                                        // Narratives
                                        var narrative = DTOFactory.NewIncidentNarrative;
                                        incidentCmdSvc.Instance.CreateIncidentNarrative(incidentId, narrative);

                                        narrative.AuthorName = "Davis, Mark";
                                        narrative.Title      = new CodeValue("Traffic Stop near McDonald's", "Traffic Stop near McDonald's");
                                        incidentCmdSvc.Instance.CreateIncidentNarrative(incidentId, narrative);

                                        // Offenses
                                        var offense = DTOFactory.NewIncidentOffense;
                                        incidentCmdSvc.Instance.CreateIncidentOffense(incidentId, offense);

                                        //offense.Description = "Assualt with a deadly weapon";
                                        incidentCmdSvc.Instance.CreateIncidentOffense(incidentId, offense);

                                        //offense.Description = "Reckless driving";
                                        incidentCmdSvc.Instance.CreateIncidentOffense(incidentId, offense);

                                        // Officers
                                        incidentCmdSvc.Instance.CreateIncidentOfficer(incidentId, DTOFactory.NewIncidentOfficer);
                                        incidentCmdSvc.Instance.CreateIncidentOfficerInvolvedShooting(incidentId, DTOFactory.NewIncidentOfficerInvolvedShooting);

                                        // Other People (Complainants)
                                        var person = DTOFactory.NewIncidentPersonOther;
                                        person.InvolvementType = new CodeValue("Complainant", "Complainant");
                                        person.FirstName       = "Mary";
                                        person.MiddleName      = "M";
                                        person.LastName        = "Davis";
                                        person.Age             = new CodeValue("25", "25");
                                        person.Race            = new CodeValue("W", "White");
                                        person.Sex             = new CodeValue("F", "Female");
                                        person.Height          = "502";
                                        person.Weight          = 130;
                                        incidentCmdSvc.Instance.CreateIncidentPersonOther(incidentId, person);

                                        person.FirstName  = "Martha";
                                        person.MiddleName = "J";
                                        person.LastName   = "Murfield";
                                        person.Age        = new CodeValue("27", "27");
                                        person.Height     = "504";
                                        person.Weight     = 124;
                                        incidentCmdSvc.Instance.CreateIncidentPersonOther(incidentId, person);

                                        // Other People (Witnesses)
                                        person.InvolvementType = new CodeValue("Witness", "Witness");
                                        person.FirstName       = "Joseph";
                                        person.MiddleName      = "T";
                                        person.LastName        = "Olaf";
                                        person.Age             = new CodeValue("34", "34");
                                        person.Race            = new CodeValue("B", "Black");
                                        person.Sex             = new CodeValue("M", "Male");
                                        person.Height          = "601";
                                        person.Weight          = 204;
                                        incidentCmdSvc.Instance.CreateIncidentPersonOther(incidentId, person);

                                        person.FirstName  = "Bart";
                                        person.MiddleName = "M";
                                        person.LastName   = "Burnes";
                                        person.Age        = new CodeValue("29", "29");
                                        person.Height     = "511";
                                        person.Weight     = 200;
                                        incidentCmdSvc.Instance.CreateIncidentPersonOther(incidentId, person);

                                        // Other People (Parents)
                                        person.InvolvementType = new CodeValue("Parent", "Parent of Victim");
                                        person.FirstName       = "Jerry";
                                        person.MiddleName      = "F";
                                        person.LastName        = "Lee";
                                        person.Age             = new CodeValue("52", "52");
                                        person.Race            = new CodeValue("W", "White");
                                        person.Sex             = new CodeValue("M", "Male");
                                        person.Height          = "600";
                                        person.Weight          = 206;
                                        incidentCmdSvc.Instance.CreateIncidentPersonOther(incidentId, person);

                                        person.FirstName  = "Lindsey";
                                        person.MiddleName = "J";
                                        person.LastName   = "Lee";
                                        person.Age        = new CodeValue("29", "29");
                                        person.Sex        = new CodeValue("F", "Female");
                                        person.Height     = "505";
                                        person.Weight     = 122;
                                        incidentCmdSvc.Instance.CreateIncidentPersonOther(incidentId, person);

                                        // Suspects
                                        var suspect = DTOFactory.NewIncidentPersonSuspect;
                                        incidentCmdSvc.Instance.CreateIncidentPersonSuspect(incidentId, suspect);

                                        suspect.FirstName  = "Johhny";
                                        suspect.MiddleName = "";
                                        suspect.LastName   = "Dean";
                                        incidentCmdSvc.Instance.CreateIncidentPersonSuspect(incidentId, suspect);

                                        // Victims
                                        var victim = DTOFactory.NewIncidentPersonVictim;
                                        incidentCmdSvc.Instance.CreateIncidentPersonVictim(incidentId, victim);

                                        victim.FirstName = "Johnson";
                                        victim.LastName  = "Smith";
                                        incidentCmdSvc.Instance.CreateIncidentOrganization(incidentId, DTOFactory.NewIncidentOrganization);

                                        // Property
                                        var property = DTOFactory.NewIncidentProperty;
                                        incidentCmdSvc.Instance.CreateIncidentProperty(incidentId, property);

                                        property.Description = "Contraband music CDs";
                                        incidentCmdSvc.Instance.CreateIncidentProperty(incidentId, property);

                                        // Vehicles
                                        var vehicle = DTOFactory.NewIncidentVehicle;
                                        vehicle.Id = incidentCmdSvc.Instance.CreateIncidentVehicle(incidentId, vehicle);

                                        vehicle       = DTOFactory.NewIncidentVehicle;
                                        vehicle.Year  = "2014";
                                        vehicle.Make  = new CodeValue("Ford", "Ford");
                                        vehicle.Model = new CodeValue("Mustang", "Mustang");
                                        vehicle.Id    = incidentCmdSvc.Instance.CreateIncidentVehicle(incidentId, vehicle);

                                        // Attachments
                                        var incAttachment = DTOFactory.NewDataEntryAttachment;
                                        incAttachment.MediaId = mediaId;
                                        //incidentCmdSvc.Instance.CreateSummaryAttachment(incidentId, incAttachment);

                                        //
                                        // Create an associated Arrest.
                                        //
                                        Guid arrestId = arrestCmdSvc.Instance.CreateArrestSummary(agencyId, caseId, DTOFactory.NewArrestSummary);
                                        arrestCmdSvc.Instance.CreateArrestAlcoholDrugTest(arrestId, DTOFactory.NewAlcoholDrugTest);
                                        arrestCmdSvc.Instance.CreateArrestArrestee(arrestId, DTOFactory.NewArrestArrestee);
                                        arrestCmdSvc.Instance.CreateArrestCharge(arrestId, DTOFactory.NewArrestCharge);
                                        arrestCmdSvc.Instance.CreateArrestDrug(arrestId, DTOFactory.NewArrestDrug);
                                        arrestCmdSvc.Instance.CreateArrestEvent(arrestId, DTOFactory.NewArrestEvent);
                                        arrestCmdSvc.Instance.CreateArrestGun(arrestId, DTOFactory.NewArrestGun);
                                        arrestCmdSvc.Instance.CreateArrestNarrative(arrestId, DTOFactory.NewArrestNarrative);
                                        arrestCmdSvc.Instance.CreateArrestOfficer(arrestId, DTOFactory.NewArrestOfficer);
                                        arrestCmdSvc.Instance.CreateArrestProperty(arrestId, DTOFactory.NewArrestProperty);
                                        arrestCmdSvc.Instance.CreateArrestVehicle(arrestId, DTOFactory.NewArrestVehicle);
                                        //var arrAttachment = DTOFactory.NewSummaryAttachment;
                                        //arrAttachment.MediaId = attachmentId;
                                        //arrestCmdSvc.Instance.CreateSummaryAttachment(arrestId, arrAttachment);

                                        //
                                        // Create an associated Field Interview.
                                        //
                                        Guid fiId = fieldInterviewCmdSvc.Instance.CreateFieldInterviewSummary(agencyId, caseId, DTOFactory.NewFieldInterviewSummary);
                                        fieldInterviewCmdSvc.Instance.CreateFieldInterviewEvent(fiId, DTOFactory.NewFieldInterviewEvent);
                                        fieldInterviewCmdSvc.Instance.CreateFieldInterviewNarrative(fiId, DTOFactory.NewFieldInterviewNarrative);
                                        fieldInterviewCmdSvc.Instance.CreateFieldInterviewOfficer(fiId, DTOFactory.NewFieldInterviewOfficer);
                                        fieldInterviewCmdSvc.Instance.CreateFieldInterviewSource(fiId, DTOFactory.NewFieldInterviewSource);
                                        fieldInterviewCmdSvc.Instance.CreateFieldInterviewVehicle(fiId, DTOFactory.NewFieldInterviewVehicle);
                                        //var fiAttachment = DTOFactory.NewSummaryAttachment;
                                        //fiAttachment.MediaId = attachmentId;
                                        //fieldInterviewCmdSvc.Instance.CreateSummaryAttachment(fiId, fiAttachment);
                                    }
            return(caseId);
        }
Пример #24
0
 public ServerResourceChangedEventProcessing(EcsWorld world, DependencyContainer dependencyContainer)
 {
     this.world = world;
     this.dependencyContainer = dependencyContainer;
 }
Пример #25
0
 protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent)
 {
     dependencies = new DependencyContainer(base.CreateLocalDependencies(parent));
     dependencies.CacheAs <IScrollingInfo>(scrollingInfo = new ScrollingInfo());
     return(dependencies);
 }
Пример #26
0
 static App()
 {
     LogConfiguration.RegisterTargets();
     Log = LogManager.GetLogger(nameof(App));
     DependencyContainer = new DependencyContainer();
 }
 protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
 {
     return(dependencies = new DependencyContainer(base.CreateChildDependencies(parent)));
 }
Пример #28
0
        public void WithValidType_ResolveType()
        {
            var container = new DependencyContainer();

            Assert.IsTrue(container.TryResolve <Fish>(out _));
        }
 public DefaultDependencyFactoriesProvider(DependencyContainer dependency_container,
                                           ConstructorSelectionStrategy constructor_selection_strategy)
 {
     this.dependency_container = dependency_container;
     this.constructor_selection_strategy = constructor_selection_strategy;
 }
Пример #30
0
        public void WithMultipleTypesAsSingleton_RegisterMultipleTypes()
        {
            var container = new DependencyContainer();

            Assert.IsNotNull(container.RegisterMultiple <IAnimal>(new[] { typeof(Monkey), typeof(Fish) }).AsSingleton());
        }
 public MagicWiringDependencyFactory(Type type_being_created, DependencyContainer container,
                                     ConstructorSelectionStrategy strategy)
 {
     this.constructor_selection_strategy = constructor_selection_strategy;
     this.the_type_that_is_being_created = the_type_that_is_being_created;
 }
Пример #32
0
        public ViewToModelMapper()
        {
            CreateMap <Views.ViewModels.UserModels.UserRegistration, IUser>()
            .ConstructUsing(viewEntity => DependencyContainer.Resolve <IUser>());

            CreateMap <IUser, Views.ViewModels.UserModels.UserRegistration>();

            CreateMap <Views.ViewModels.UserModels.AccountInfo, IUser>()
            .ConstructUsing(viewEntity => DependencyContainer.Resolve <IUser>());

            CreateMap <IUser, Views.ViewModels.UserModels.AccountInfo>();


            CreateMap <Views.ViewModels.ApartmentModels.CreateApartment, IApartment>()
            .ConstructUsing(viewEntity => DependencyContainer.Resolve <IApartment>());

            CreateMap <IApartment, Views.ViewModels.ApartmentModels.CreateApartment>();

            CreateMap <Views.ViewModels.ApartmentModels.UpdateApartment, IApartment>()
            .ForMember(apartment => apartment.Id, mapper => mapper.MapFrom(src => src.ApartmentId))
            .ConstructUsing(viewEntity => DependencyContainer.Resolve <IApartment>());

            CreateMap <IApartment, Views.ViewModels.ApartmentModels.UpdateApartment>()
            .ForMember(apartment => apartment.ApartmentId, mapper => mapper.MapFrom(src => src.Id));


            CreateMap <IPicture, Views.ViewModels.ApartmentModels.ApartmentPicture>();

            CreateMap <Views.ViewModels.ApartmentModels.ApartmentPicture, IPicture>()
            .ConstructUsing(viewEntity => DependencyContainer.Resolve <IPicture>());

            CreateMap <IAvailableDate, Views.ViewModels.ApartmentModels.AvailableDates>();

            CreateMap <Views.ViewModels.ApartmentModels.AvailableDates, IAvailableDate>()
            .ConstructUsing(viewEntity => DependencyContainer.Resolve <IAvailableDate>());

            CreateMap <IComment, Views.ViewModels.ApartmentModels.Comment>();

            CreateMap <Views.ViewModels.ApartmentModels.Comment, IComment>()
            .ConstructUsing(viewEntity => DependencyContainer.Resolve <IComment>());

            CreateMap <Facility, Views.ViewModels.ApartmentModels.Facility>()
            .ForMember(facility => facility.Title, mapper => mapper.MapFrom(src => src.ToString()));

            CreateMap <Views.ViewModels.ApartmentModels.Facility, Facility>()
            .ConstructUsing(viewEntity => DependencyContainer.Resolve <Facility>());

            CreateMap <IApartment, Views.ViewModels.ApartmentModels.AvailableApartmentInfo>()
            .ForMember(apartment => apartment.Comments, mapper => mapper.MapFrom(src => src.Comments))
            .ForMember(apartment => apartment.Pictures, mapper => mapper.MapFrom(src => src.Pictures))
            .ForMember(apartment => apartment.Facilities, mapper => mapper.MapFrom(src =>
                                                                                   Enum.GetValues(typeof(Facility))
                                                                                   .Cast <Facility>()
                                                                                   .Where(option => (src.Facilities & option) == option)
                                                                                   .Select(option => new Views.ViewModels.ApartmentModels.Facility {
                Title = option.ToString()
            })));

            CreateMap <IApartment, Views.ViewModels.ApartmentModels.ApartmentInfo>()
            .ForMember(apartment => apartment.Comments, mapper => mapper.MapFrom(src => src.Comments))
            .ForMember(apartment => apartment.Pictures, mapper => mapper.MapFrom(src => src.Pictures))
            .ForMember(apartment => apartment.Facilities, mapper => mapper.MapFrom(src =>
                                                                                   Enum.GetValues(typeof(Facility))
                                                                                   .Cast <Facility>()
                                                                                   .Where(option => (src.Facilities & option) == option)
                                                                                   .Select(option => new Views.ViewModels.ApartmentModels.Facility {
                Title = option.ToString()
            })));


            CreateMap <IContract, Views.ViewModels.UserModels.Contract>()
            .ForMember(contract => contract.ContractStatus, mapper => mapper.MapFrom(src =>
                                                                                     new Views.ViewModels.ApartmentModels.ContractStatus {
                Status = src.ContractStatus.ToString()
            }));

            CreateMap <Views.ViewModels.UserModels.Contract, IContract>()
            .ConstructUsing(viewEntity => DependencyContainer.Resolve <IContract>());
        }
Пример #33
0
        public void WithObject_ResolveType(Type resolveType, bool expected)
        {
            var container = new DependencyContainer();

            Assert.AreEqual(expected, container.TryResolve(resolveType, out _));
        }
Пример #34
0
 public BrokerAccount()
 {
     DependencyContainer.ComposeParts(this);
 }
Пример #35
0
        private IWebHostBuilder CreateWebHostBuilder
        (
            ICollection <Action <IConfiguration> > configuration,
            ICollection <Action <IServiceCollection> > configureServices,
            ICollection <Action <IApplicationBuilder> > configure,
            SystemTopology topology)
        {
            T startup = null;
            IConfiguration      config   = null;
            IServiceCollection  services = null;
            IWebHostEnvironment env;

            var builder = new WebHostBuilder()
                          .ConfigureAppConfiguration((context, cb) =>
            {
                env = context.HostingEnvironment;
                var testSettings = BuildTestSettings(env.ContentRootPath, env.EnvironmentName);
                ConfigureAppConfiguration(env, testSettings, cb);
                config = cb.Build();
            })
                          .ConfigureServices(serviceCollection =>
            {
                services = serviceCollection;

                Debug.Assert(services != null);
                Debug.Assert(config != null);

                var serviceProvider = serviceCollection.BuildServiceProvider();
                Debug.Assert(serviceProvider != null);

                var container = new DependencyContainer(serviceProvider);

                container.Register(serviceProvider);
                container.Register(services);
                container.Register(config);

                startup = container.Resolve <T>();
                Debug.Assert(startup != null);
                foreach (var action in configuration)
                {
                    action(config);
                }

                container.Register(startup);

                var method = startup.GetType().GetMethod("ConfigureServices");
                if (method != null)
                {
                    var accessor = CallAccessor.Create(method);
                    accessor.Call(startup);
                }

                foreach (var action in configureServices)
                {
                    action(serviceCollection);
                }
            });

            if (topology == SystemTopology.Web)
            {
                builder.Configure(app =>
                {
                    Debug.Assert(services != null);
                    Debug.Assert(config != null);
                    Debug.Assert(startup != null);
                    Debug.Assert(app != null);

                    var serviceProvider = services.BuildServiceProvider();
                    Debug.Assert(serviceProvider != null);

                    var container = new DependencyContainer(serviceProvider);

                    container.Register(serviceProvider);
                    container.Register(services);
                    container.Register(config);
                    container.Register(startup);
                    container.Register(app);

                    var method = startup.GetType().GetMethod("Configure");
                    if (method != null)
                    {
                        var accessor = CallAccessor.Create(method);
                        accessor.Call(startup);
                    }
                    foreach (var action in configure)
                    {
                        action(app);
                    }
                });
            }

            UseAssemblyForSetting <T>(builder, WebHostDefaults.ApplicationKey);
            UseAssemblyForSetting <T>(builder, WebHostDefaults.StartupAssemblyKey);

            Services = services;

            return(builder);
        }
Пример #36
0
        public void WithInvalidType_FailResolveType()
        {
            var container = new DependencyContainer();

            Assert.IsFalse(container.TryResolve <IAnimal>(out _));
        }
Пример #37
0
        public void BeforeEach()
        {
            // mock data
            mockDataRepo = new Mock <IDataRepository>().SetupGetAll(UserHelpers.CreateUsers());

            mockUserLogRecord = new Mock <IUserLogger>();

            // service under test
            testUserRepo =
                new ModernSlavery.Infrastructure.Database.Classes.UserRepository(new DatabaseOptions(), new SharedOptions(),
                                                                                 mockDataRepo.Object, mockUserLogRecord.Object, DependencyContainer.Resolve <IMapper>());
        }
Пример #38
0
 public _Default()
 {
     this.logger = DependencyContainer.GetService <ILogger <_Default> >();
 }