public OrganizationsControllerTests()
        {
            var list = new List <Organization>
            {
                new Organization {
                    Id = 1, Name = "test 1"
                },
                new Organization {
                    Id = 2, Name = "test 2"
                }
            }.AsQueryable();

            var mockContext            = Substitute.For <TtContext>();
            var organizationRepository = Substitute.For <Repository <Organization> >(mockContext);

            _service = Substitute.For <OrganizationService>(organizationRepository);
            _service.GetList().Returns(list);
            _service.GetItem(Arg.Any <int>()).Returns(new Organization {
                Id = 1, Name = "test 1"
            });
            _service.Create(Arg.Any <Organization>());
            _service.Update(Arg.Any <int>(), Arg.Any <Organization>());
            _service.Delete(Arg.Any <int>());

            var mockLogger = Substitute.For <ILoggerFactory>();

            _controller = new OrganizationsController(_service, mockLogger);
        }
Ejemplo n.º 2
0
        public void GetOrganizationEdit_ShouldReturnEdit()
        {
            var organizationsTestData = new List <Organization>()
            {
                new Organization {
                    Id = 1
                },
                new Organization {
                    Id = 2, Deleted = true
                },
                new Organization {
                    Id = 3
                }
            };
            var organizations = MockHelper.MockDbSet(organizationsTestData);

            organizations.Setup(d => d.Find(It.IsAny <object>())).Returns <object[]>((keyValues) => { return(organizations.Object.SingleOrDefault(product => product.Id == (int)keyValues.Single())); });
            var dbContext = new Mock <IAppDbContext>();

            dbContext.Setup(m => m.Organizations).Returns(organizations.Object);
            dbContext.Setup(d => d.Set <Organization>()).Returns(organizations.Object);
            var factory = new Mock <IDbContextFactory>();

            factory.Setup(m => m.CreateDbContext()).Returns(dbContext.Object);
            var controller = new OrganizationsController(factory.Object);
            var result     = controller.GetOrganizationEdit(1) as OkNegotiatedContentResult <OrganizationEditDTO>;

            Assert.AreEqual(1, result.Content.Id);
        }
Ejemplo n.º 3
0
        public static async Task InsertNewOrgTest()
        {
            await Networks.NetworkTests.InsertNewNetworkTest();

            string filepath = System.IO.Path.Combine(ResourceFolder, "OrganizationsRegister.json");
            var    json     = System.IO.File.ReadAllText(filepath);

            Newtonsoft.Json.JsonSerializerSettings jsonSettings = new Newtonsoft.Json.JsonSerializerSettings();
            jsonSettings.DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.IgnoreAndPopulate;
            OrgList orgs       = Newtonsoft.Json.JsonConvert.DeserializeObject <OrgList>(json, jsonSettings);
            var     controller = new OrganizationsController();

            foreach (var org in orgs.Organizations)
            {
                var response = await controller.Register(org);

                OrgPair.Add(new KeyValuePair <Guid, Guid>(org.ID, response.ID.Value));
                using (var db = new Data.DataContext())
                {
                    var orgGet = await db.Organizations.FindAsync(response.ID);

                    var metaData = await db.DomainDatas.OfType <Data.OrganizationDomainData>().Where(x => x.OrganizationID == response.ID).ToArrayAsync();

                    Assert.IsTrue(!orgGet.IsEmpty());
                    Assert.IsTrue(metaData.Count() > 0);
                }
            }
        }
 public void Init()
 {
     mediator   = Substitute.For <IMediator>();
     controller = new OrganizationsController(mediator)
     {
         Logger = Substitute.For <ILogger>()
     };
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OrganizationsControllerTest" /> class.
        /// </summary>
        public OrganizationsControllerTest()
        {
            this.entitiesForTest = new EntitiesForTest();
            this.repositoryMock  = new Mock <IRepository <Organization> >();
            this.mapperMock      = new Mock <IMapper>();

            this.target = new OrganizationsController(
                this.repositoryMock.Object,
                this.mapperMock.Object);
        }
Ejemplo n.º 6
0
        public void TestInit()
        {
            organizationService     = new Mock <IOrganizationService>();
            organizationTypeService = new Mock <IOrganizationTypeService>();
            userProvider            = new Mock <IUserProvider>();
            addressHandler          = new Mock <IAddressModelHandler>();
            socialMediaHandler      = new Mock <ISocialMediaPresenceModelHandler>();
            organizationService.Setup(x => x.GetOrganizationsAsync(It.IsAny <QueryableOperator <SimpleOrganizationDTO> >()))
            .ReturnsAsync(new PagedQueryResults <SimpleOrganizationDTO>(1, new List <SimpleOrganizationDTO>()));

            controller = new OrganizationsController(organizationService.Object, organizationTypeService.Object, userProvider.Object, addressHandler.Object, socialMediaHandler.Object);
        }
Ejemplo n.º 7
0
        public async Task GetSummaries_should_return_list_of_OranizationSummary_objects()
        {
            var organizationsServiceMock = new Mock <IOrganizationsService>();

            organizationsServiceMock
            .Setup(o => o.GetAllSummaries())
            .ReturnsAsync(() => new List <OrganizationSummary>());

            var controller = new OrganizationsController(organizationsServiceMock.Object);

            var result = await controller.GetSummaries();

            Assert.True(result.GetType() == typeof(List <OrganizationSummary>), "GetSummaries does not return a list of OranizationSummary objects");
        }
Ejemplo n.º 8
0
        public async void TestGetOrgConfigTypeAsync()
        {
            //Arrange
            var mockConfigService = new Mock <IConfigService>();

            mockConfigService.Setup(service => service.GetOrganizationsAsync()).ReturnsAsync(GetOrganizationObject());

            var orgController = new OrganizationsController();

            //Act
            var actual = await orgController.GetOrgConfigAsync(mockConfigService.Object);

            //Assert
            Assert.IsType <Organization>(actual.Value.ElementAt(0));
        }
Ejemplo n.º 9
0
        public async void TestGetOrgConfigNotNullAsync()
        {
            //Arrange
            var mockConfigService = new Mock <IConfigService>();

            mockConfigService.Setup(service => service.GetOrganizationsAsync()).ReturnsAsync(GetOrganizationObject());

            var orgController = new OrganizationsController();

            //Act
            var actual = await orgController.GetOrgConfigAsync(mockConfigService.Object);

            //Assert
            mockConfigService.VerifyAll();
            Assert.NotNull(actual);
        }
Ejemplo n.º 10
0
        public OrganizationsControllerTests()
        {
            _currentContext             = Substitute.For <ICurrentContext>();
            _globalSettings             = Substitute.For <GlobalSettings>();
            _organizationRepository     = Substitute.For <IOrganizationRepository>();
            _organizationService        = Substitute.For <IOrganizationService>();
            _organizationUserRepository = Substitute.For <IOrganizationUserRepository>();
            _paymentService             = Substitute.For <IPaymentService>();
            _policyRepository           = Substitute.For <IPolicyRepository>();
            _ssoConfigRepository        = Substitute.For <ISsoConfigRepository>();
            _ssoConfigService           = Substitute.For <ISsoConfigService>();
            _userService = Substitute.For <IUserService>();

            _sut = new OrganizationsController(_organizationRepository, _organizationUserRepository,
                                               _policyRepository, _organizationService, _userService, _paymentService, _currentContext,
                                               _ssoConfigRepository, _ssoConfigService, _globalSettings);
        }
Ejemplo n.º 11
0
        public async void TestOrgNameAndOrgIdAsync()
        {
            //Arrange
            var mockConfigService = new Mock <IConfigService>();

            mockConfigService.Setup(service => service.GetOrganizationsAsync()).ReturnsAsync(GetOrganizationObject());

            var orgController = new OrganizationsController();
            var expected      = GetOrganizationObject();

            //Act
            var actual = await orgController.GetOrgConfigAsync(mockConfigService.Object);

            //Assert
            Assert.True(actual.Value.ElementAt(0).OrgId == expected.ElementAt(0).OrgId&&
                        actual.Value.ElementAt(0).OrgName == expected.ElementAt(0).OrgName);
        }
        public async Task AddOrganizationTest()
        {
            var options = this.CreateInMemoryDatabase("Add_Organizations_Database");

            using (var _context = new IronChurchContext(options))
            {
                OrganizationsController orgController = new OrganizationsController(_context);

                var ExpectedOrg = new Organization {
                    Name = "Sam Test 1"
                };

                var result = await orgController.PostOrganization(ExpectedOrg);

                var ActualOrganization = orgController.GetOrganization().Result.Where(x => x.OrganizationId == 31).FirstOrDefault();

                Assert.AreEqual(ExpectedOrg.Name, ActualOrganization.Name);
            }
        }
Ejemplo n.º 13
0
        public async Task Get_Id_GetsOrganization(
            bool exists,
            Type resultType
            )
        {
            var id = 1;

            var returns        = exists ? new Organization() : null;
            var _organizations = new Mock <IOrganizationRepository>();

            _organizations.Setup(o => o.GetOrganizationByIdAsync(id))
            .ReturnsAsync(returns);

            var controller = new OrganizationsController(_organizations.Object);

            var result = await controller.Get(id);

            _organizations.Verify(o => o.GetOrganizationByIdAsync(id), Times.Once());
            Assert.IsType(resultType, result.Result);
        }
Ejemplo n.º 14
0
        public void Get_Id_Include_GetsOrganization_WithInclude(
            bool exists,
            Type resultType
            )
        {
            var id      = 1;
            var include = new string[] { "foo" };

            var returns        = exists ? new Organization() : null;
            var _organizations = new Mock <IOrganizationRepository>();

            _organizations.Setup(o => o.GetOrganizationById(id, include))
            .Returns(returns);

            var controller = new OrganizationsController(_organizations.Object);

            var result = controller.Get(id, include);

            _organizations.Verify(o => o.GetOrganizationById(id, include), Times.Once());
            Assert.IsType(resultType, result.Result);
        }
Ejemplo n.º 15
0
        public MegaClass(
            UserLicensesController a2,
            TimeEntrySuggestedRowsController a3,
            WorkHourSuggestedRowsController a4,
            KpiFormulasController a5,
            UserSettingsController a6,
            SecurityController a7,
            SoapApiKeysController a8,
            NotificationSettingsController a9,
            FlextimeAdjustmentsController a10,
            AuthorizedIpAddressesController a11,
            BankAccountsController a12,
            ApiClientsController a13,
            OrganizationSettingsController a14,
            LogosController a15,
            ProjectMemberCostExceptionsController a16,
            OrganizationDetailsController a17,
            AddonsController a18,
            TravelExpenseCountrySettingsController a19,
            ProductCountrySettingsController a20,
            CustomerCountrySettingsController a21,
            KpiComparisonController a22,
            TravelExpenseReceiptsController a23,
            TravelReimbursementStatusController a24,
            TravelReimbursementsController a25,
            ResourcingOverviewController a26,
            TermsOfServiceApprovalsController a27,
            FinancialsController a28,
            CalendarGroupMembersController a29,
            ActivityParticipantsController a30,
            ActivitiesController a31,
            PermissionProfilesController a32,
            CalendarGroupsController a33,
            ResourcesController a34,
            DemoDataController a35,
            LinksController a36,
            ReimbursedWorkHoursController a37,
            ReimbursedProjectTravelExpensesController a38,
            ReimbursedProjectFeesController a39,
            ProjectsOverviewController a40,
            ContactRolesController a41,
            CustomerMarketSegmentsController a42,
            ProjectTotalFeesController a43,
            BillingInformationUpdateController a44,
            KeywordsController a45,
            FlatRatesController a46,
            BusinessOverviewController a47,
            SpecialUserOptionsController a48,
            UninvoicedProjectsController a49,
            TeamProductivityController a50,
            ProjectBillingCustomersController a51,
            MarketSegmentsController a52,
            ProjectProductsController a53,
            ScheduleOverviewController a54,
            SharedDashboardAccessRightProfilesController a55,
            SharedDashboardsController a56,
            InvoicesOverviewController a57,
            ProposalBillingPlanController a58,
            SalesOverviewController a59,
            CustomersOverviewController a60,
            ProposalProjectPlanController a61,
            TimeEntryTypesController a62,
            CommunicationTypesController a63,
            ContactCommunicationsController a64,
            FlextimeController a65,
            ProjectForecastsController a66,
            ResourceAllocationsController a67,
            TemporaryProjectFeesController a68,
            InvoiceTemplateSettingsController a69,
            TemporaryProjectTravelExpensesController a70,
            TemporaryWorkHoursController a71,
            InvoiceTemplatesController a72,
            WorkdaysController a73,
            InvoiceSettingsController a74,
            OrganizationsController a75,
            ProjectTaskStatusesController a76,
            ActivityTypesController a77,
            AddressesController a78,
            DashboardPartsController a79,
            DashboardWithPartsController a80,
            DashboardsController a81,
            InvoiceRowsController a82,
            InvoicesController a83,
            HolidaysController a84,
            PermissionsController a85,
            QuickSearchController a86,
            ProposalTemplatesController a87,
            InvoiceTotalsController a88,
            ProposalTotalsController a89,
            ProposalWorkhoursController a90,
            ProposalSubtotalsController a91,
            ProposalFeesController a92,
            ReportsController a93,
            ProposalStatusesController a94,
            InvoiceStatusesController a95,
            ProposalsController a96,
            StatusHistoryController a97,
            PhaseStatusTypesController a98,
            CostCentersController a99,
            ProjectWorktypesController a100,
            PricelistVersionsController a101,
            OvertimePricesController a102,
            AllUsersController a103,
            TimeEntriesController a104,
            WorkTypesController a105,
            WorkHoursController a106,
            ProjectWorkHourPricesController a107,
            TravelPricesController a108,
            WorkHourPricesController a109,
            ProductPricesController a110,
            ProjectRecurringFeeRulesController a111,
            ProjectTravelExpensesController a112,
            TravelExpensesController a113,
            ProjectFeesController a114,
            SalesReceivableAccountsController a115,
            ValueAddedTaxesController a116,
            ProductsController a117,
            BusinessUnitsController a118,
            CollaborationNotesController a119,
            ContactsController a120,
            CurrencyBasesController a121,
            CurrenciesController a122,
            CountriesController a123,
            CustomersController a124,
            FileDataController a125,
            FilesController a126,
            FormattingCulturesController a127,
            IndustriesController a128,
            LanguagesController a129,
            LeadSourcesController a130,
            MenuController a131,
            PersonalSettingsController a132,
            PhaseMembersController a133,
            PhasesController a134,
            PricelistsController a135,
            OvertimesController a136,
            ProjectsController a137,
            ProjectStatusTypesController a138,
            SalesAccountsController a139,
            SalesNotesController a140,
            ProductCategoriesController a141,
            WorkContractsController a142,
            SalesStatusController a143,
            SalesStatusTypeController a144,
            TimeZonesController a145,
            UsersController a146,
            ScheduledWorkJobsController a147,
            PasswordChangeController a148,
            UserInactivationInformationController a149,
            EmailAddressChangeController a150,
            EmailController a151,
            PdfController a152,
            BearerAuthenticationController a153,
            ExternalAuthenticationController a154,
            HeartBeatController a155

            )
        {
            _a2   = _a2;
            _a3   = _a3;
            _a4   = _a4;
            _a5   = _a5;
            _a6   = _a6;
            _a7   = _a7;
            _a8   = _a8;
            _a9   = _a9;
            _a10  = _a10;
            _a11  = _a11;
            _a12  = _a12;
            _a13  = _a13;
            _a14  = _a14;
            _a15  = _a15;
            _a16  = _a16;
            _a17  = _a17;
            _a18  = _a18;
            _a19  = _a19;
            _a20  = _a20;
            _a21  = _a21;
            _a22  = _a22;
            _a23  = _a23;
            _a24  = _a24;
            _a25  = _a25;
            _a26  = _a26;
            _a27  = _a27;
            _a28  = _a28;
            _a29  = _a29;
            _a30  = _a30;
            _a31  = _a31;
            _a32  = _a32;
            _a33  = _a33;
            _a34  = _a34;
            _a35  = _a35;
            _a36  = _a36;
            _a37  = _a37;
            _a38  = _a38;
            _a39  = _a39;
            _a40  = _a40;
            _a41  = _a41;
            _a42  = _a42;
            _a43  = _a43;
            _a44  = _a44;
            _a45  = _a45;
            _a46  = _a46;
            _a47  = _a47;
            _a48  = _a48;
            _a49  = _a49;
            _a50  = _a50;
            _a51  = _a51;
            _a52  = _a52;
            _a53  = _a53;
            _a54  = _a54;
            _a55  = _a55;
            _a56  = _a56;
            _a57  = _a57;
            _a58  = _a58;
            _a59  = _a59;
            _a60  = _a60;
            _a61  = _a61;
            _a62  = _a62;
            _a63  = _a63;
            _a64  = _a64;
            _a65  = _a65;
            _a66  = _a66;
            _a67  = _a67;
            _a68  = _a68;
            _a69  = _a69;
            _a70  = _a70;
            _a71  = _a71;
            _a72  = _a72;
            _a73  = _a73;
            _a74  = _a74;
            _a75  = _a75;
            _a76  = _a76;
            _a77  = _a77;
            _a78  = _a78;
            _a79  = _a79;
            _a80  = _a80;
            _a81  = _a81;
            _a82  = _a82;
            _a83  = _a83;
            _a84  = _a84;
            _a85  = _a85;
            _a86  = _a86;
            _a87  = _a87;
            _a88  = _a88;
            _a89  = _a89;
            _a90  = _a90;
            _a91  = _a91;
            _a92  = _a92;
            _a93  = _a93;
            _a94  = _a94;
            _a95  = _a95;
            _a96  = _a96;
            _a97  = _a97;
            _a98  = _a98;
            _a99  = _a99;
            _a100 = _a100;
            _a101 = _a101;
            _a102 = _a102;
            _a103 = _a103;
            _a104 = _a104;
            _a105 = _a105;
            _a106 = _a106;
            _a107 = _a107;
            _a108 = _a108;
            _a109 = _a109;
            _a110 = _a110;
            _a111 = _a111;
            _a112 = _a112;
            _a113 = _a113;
            _a114 = _a114;
            _a115 = _a115;
            _a116 = _a116;
            _a117 = _a117;
            _a118 = _a118;
            _a119 = _a119;
            _a120 = _a120;
            _a121 = _a121;
            _a122 = _a122;
            _a123 = _a123;
            _a124 = _a124;
            _a125 = _a125;
            _a126 = _a126;
            _a127 = _a127;
            _a128 = _a128;
            _a129 = _a129;
            _a130 = _a130;
            _a131 = _a131;
            _a132 = _a132;
            _a133 = _a133;
            _a134 = _a134;
            _a135 = _a135;
            _a136 = _a136;
            _a137 = _a137;
            _a138 = _a138;
            _a139 = _a139;
            _a140 = _a140;
            _a141 = _a141;
            _a142 = _a142;
            _a143 = _a143;
            _a144 = _a144;
            _a145 = _a145;
            _a146 = _a146;
            _a147 = _a147;
            _a148 = _a148;
            _a149 = _a149;
            _a150 = _a150;
            _a151 = _a151;
            _a152 = _a152;
            _a153 = _a153;
            _a154 = _a154;
            _a155 = _a155;
        }
        public void Init()
        {
            var automapperConfig = new AutoMapperConfig();
            automapperConfig.Execute(typeof(OrganizationsController).Assembly);

            var organizations = new Mock<IOrganizationsService>();
            organizations.Setup(x => x.Edit(It.IsAny<int>(), It.IsAny<string>()))
                .Returns(new Organization
                {
                    Id = 42
                });

            organizations.Setup(x => x.GetAll())
                .Returns(new List<Organization> {
                       new Organization {
                            Id = 42
                        }
                    }.AsQueryable());

            organizations.Setup(x => x.GetAllWithDeleted())
                .Returns(new List<Organization> {
                       new Organization {
                            Id = 42
                        }
                    }.AsQueryable());

            this.controller = new OrganizationsController(organizations.Object);
        }
Ejemplo n.º 17
0
        public static async Task UpdateNewOrgTest()
        {
            string filepath = System.IO.Path.Combine(ResourceFolder, "OrganizationsUpdate.json");
            var    json     = System.IO.File.ReadAllText(filepath);

            Newtonsoft.Json.JsonSerializerSettings jsonSettings = new Newtonsoft.Json.JsonSerializerSettings();
            jsonSettings.DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.IgnoreAndPopulate;
            OrgList orgs       = Newtonsoft.Json.JsonConvert.DeserializeObject <OrgList>(json, jsonSettings);
            var     controller = new OrganizationsController();

            foreach (var org in orgs.Organizations)
            {
                using (var db = new Data.DataContext())
                {
                    var orgID = OrgPair.Where(x => x.Key == org.ID).Select(x => x.Value).FirstOrDefault();
                    org.ID = orgID;
                    var metadatas    = db.DomainDatas.OfType <Data.OrganizationDomainData>().Where(x => x.OrganizationID == orgID).ToArray();
                    var newMetaDatas = new List <DomainDataDTO>();
                    foreach (var metadata in metadatas)
                    {
                        if (metadata.DomainUseID == new Guid("082C0001-C179-4630-A0C9-A6560123AFC6") || metadata.DomainReferenceID == new Guid("16C392E9-FF26-47C6-AE6F-A62600B48C85"))
                        {
                            var meta = new DomainDataDTO();
                            meta.Value          = metadata.Value + " Update Test";
                            meta.SequenceNumber = 0;
                            meta.ID             = metadata.ID;
                            meta.DomainUseID    = metadata.DomainUseID;
                            if (metadata.DomainReferenceID.HasValue)
                            {
                                meta.DomainReferenceID = metadata.DomainReferenceID.Value;
                            }
                            newMetaDatas.Add(meta);
                        }
                        else if (metadata.DomainReferenceID == new Guid("BF140BF4-91BF-41F0-BA4A-A62600AED2B9") || metadata.DomainReferenceID == new Guid("B7236848-CA4E-4F5F-B482-A62600AEC6C6"))
                        {
                            //Intensionally leaving this blank to not put into newMetaDatas List.
                        }
                        else if (org.ID == new Guid("CD50B39C-9A9E-48FB-91D0-A62700F623B0"))
                        {
                            var meta = new DomainDataDTO()
                            {
                                DomainUseID       = Guid.Parse("B5D00001-6085-44DA-8162-A6560124D48D"),
                                DomainReferenceID = Guid.Parse("95414CD3-B661-4F91-8957-A62600B243D9"),
                                SequenceNumber    = 0
                            };
                            newMetaDatas.Add(meta);
                        }
                        else if (org.ID == new Guid("8EDD0AF4-29CE-4B82-8D85-A62700F8EFDF"))
                        {
                            var meta = new DomainDataDTO()
                            {
                                DomainUseID       = Guid.Parse("B5D00001-6085-44DA-8162-A6560124D48D"),
                                DomainReferenceID = Guid.Parse("F108307B-B8C5-4DE4-A6E8-A62600B25065"),
                                Value             = "LPP Types of Data",
                                SequenceNumber    = 0
                            };
                            newMetaDatas.Add(meta);
                        }
                        else
                        {
                            //This is filling in all the rest to remain untouched
                            var meta = new DomainDataDTO()
                            {
                                ID             = metadata.ID,
                                DomainUseID    = metadata.DomainUseID,
                                Value          = metadata.Value,
                                SequenceNumber = metadata.SequenceNumber
                            };
                            if (metadata.DomainReferenceID.HasValue)
                            {
                                meta.DomainReferenceID = metadata.DomainReferenceID;
                            }
                            newMetaDatas.Add(meta);
                        }
                    }
                    org.Metadata = newMetaDatas;



                    var response = await controller.Update(org);

                    var orgGet = await db.Organizations.FindAsync(orgID);

                    var metaData = await db.DomainDatas.OfType <Data.OrganizationDomainData>().Where(x => x.OrganizationID == orgID).ToArrayAsync();

                    Assert.IsTrue(!orgGet.IsEmpty());
                    Assert.IsTrue(metaData.Count() > 0);
                }
            }
        }
Ejemplo n.º 18
0
        public void PostProperty_ShoulAddProperty()
        {
            var organizationsTestData = new List <Organization>()
            {
                new Organization {
                    Id = 1
                },
                new Organization {
                    Id = 2, Deleted = true
                },
                new Organization {
                    Id = 3
                }
            };
            var organizations = MockHelper.MockDbSet(organizationsTestData);

            organizations.Setup(d => d.Find(It.IsAny <object>())).Returns <object[]>((keyValues) => { return(organizations.Object.SingleOrDefault(product => product.Id == (int)keyValues.Single())); });
            organizations.Setup(d => d.Add(It.IsAny <Organization>())).Returns <Organization>((contact) =>
            {
                organizationsTestData.Add(contact);
                organizations = MockHelper.MockDbSet(organizationsTestData);
                return(contact);
            });

            var dbContext = new Mock <IAppDbContext>();

            dbContext.Setup(m => m.Organizations).Returns(organizations.Object);
            dbContext.Setup(d => d.Set <Organization>()).Returns(organizations.Object);



            dbContext.Setup(d => d.ExecuteStoredProcedure <int>(It.IsAny <string>(), It.IsAny <object[]>()))
            .Returns <string, object[]>((query, parameters) =>
            {
                List <int> list = new List <int>();
                if (query.Contains("NewTableId"))
                {
                    int i = organizations.Object.Max(d => d.Id) + 1;
                    list.Add(i);
                }
                else
                {
                    list.Add(0);
                }
                return(list);
            });

            var factory = new Mock <IDbContextFactory>();

            factory.Setup(m => m.CreateDbContext()).Returns(dbContext.Object);
            Organization passport = new Organization {
                Id = 0
            };

            var identityHelper = new Mock <IIdentityHelper>();

            identityHelper.Setup(d => d.GetUserTableId(It.IsAny <IPrincipal>())).Returns(11);
            identityHelper.Setup(d => d.GetUserTableName(It.IsAny <IPrincipal>())).Returns("Employee");


            var controller = new OrganizationsController(factory.Object, identityHelper.Object);
            var result     = controller.PostOrganization(passport.MapToEdit()) as CreatedAtRouteNegotiatedContentResult <OrganizationEditDTO>;

            Assert.IsNotNull(result);
            Assert.AreEqual(4, result.Content.Id);
        }
 public void Init()
 {
     this.organizations = ObjectFactory.GetOrganizationService();
     this.controller = new OrganizationsController(organizations);
 }
Ejemplo n.º 20
0
        public void GetOrganizatioByOfficeIds_ShoulReturn()
        {
            var organizationsTestData = new List <Organization>()
            {
                new Organization {
                    Id = 1
                },
                new Organization {
                    Id = 2, Deleted = true
                },
                new Organization {
                    Id = 3
                }
            };
            var organizations = MockHelper.MockDbSet(organizationsTestData);

            var dbContext = new Mock <IAppDbContext>();

            dbContext.Setup(m => m.Organizations).Returns(organizations.Object);
            dbContext.Setup(d => d.Set <Organization>()).Returns(organizations.Object);
            dbContext.Setup(d => d.ExecuteStoredProcedure <OrganizationView>(It.IsAny <string>(), It.IsAny <object[]>()))
            .Returns <string, object[]>((query, parameters) =>
            {
                List <OrganizationView> list = new List <OrganizationView>();
                if (query.Contains("OrganizationByOfficeIds"))
                {
                    list.Add(new OrganizationView {
                        Id = 1, NativeName = "ss"
                    });
                    list.Add(new OrganizationView {
                        Id = 2, NativeName = "ss"
                    });
                    list.Add(new OrganizationView {
                        Id = 3, NativeName = "ss"
                    });
                    list.Add(new OrganizationView {
                        Id = 4, NativeName = "ss"
                    });
                    list.Add(new OrganizationView {
                        Id = 5, NativeName = "ss"
                    });
                    list.Add(new OrganizationView {
                        Id = 6, NativeName = "ss"
                    });
                }
                else
                {
                    list.Add(new OrganizationView {
                        Id = 1, NativeName = "ss"
                    });
                }
                return(list);
            });

            var factory = new Mock <IDbContextFactory>();

            factory.Setup(m => m.CreateDbContext()).Returns(dbContext.Object);
            var controller = new OrganizationsController(factory.Object);

            var result = controller.GetOrganizationByOfficeIds("1,2") as OkNegotiatedContentResult <IEnumerable <OrganizationView> >;

            Assert.AreEqual(6, result.Content.Count());
        }
 public void Init()
 {
     this.organizations = ObjectFactory.GetOrganizationService();
     this.controller    = new OrganizationsController(organizations);
 }
Ejemplo n.º 22
0
        public void GetOrganizationView_ShouldReturnView()
        {
            //жопа
            var addrTestData = new List <OrganizationAddress>()
            {
                new OrganizationAddress {
                    Id = 1
                }
            };
            var addresses = MockHelper.MockDbSet(addrTestData);

            var cpTestData = new List <OrganizationContactPerson>()
            {
                new OrganizationContactPerson {
                    Id = 1
                }
            };
            var contactPersons = MockHelper.MockDbSet(cpTestData);


            var contactsTestData = new List <OrganizationContactPersonContact>()
            {
                new OrganizationContactPersonContact {
                    Id = 1
                }
            };
            var contacts = MockHelper.MockDbSet(contactsTestData);

            var linksTestData = new List <OrganizationGTILink>()
            {
                new OrganizationGTILink {
                    Id = 1
                }
            };
            var links = MockHelper.MockDbSet(linksTestData);

            var ogsgtiTestData = new List <OrganizationGTI>()
            {
                new OrganizationGTI {
                    Id = 1
                }
            };
            var orgs = MockHelper.MockDbSet(ogsgtiTestData);

            var officesTestData = new List <Office>()
            {
                new Office {
                    Id = 1
                }
            };
            var offices = MockHelper.MockDbSet(officesTestData);

            var propsTestData = new List <OrganizationProperty>()
            {
                new OrganizationProperty {
                    Id = 1
                }
            };
            var properties = MockHelper.MockDbSet(propsTestData);


            var taxAddressesTestData = new List <OrganizationTaxAddress>()
            {
                new OrganizationTaxAddress {
                    Id = 1
                }
            };
            var taxAddresses = MockHelper.MockDbSet(taxAddressesTestData);

            var namesTestData = new List <OrganizationLanguageName>()
            {
                new OrganizationLanguageName {
                    Id = 1
                }
            };
            var names = MockHelper.MockDbSet(namesTestData);


            var cpViewsTestData = new List <OrganizationContactPersonView>()
            {
                new OrganizationContactPersonView {
                    Id = 1
                }
            };
            var cpViews = MockHelper.MockDbSet(cpViewsTestData);


            var organizationsTestData = new List <Organization>()
            {
                new Organization {
                    Id = 1
                },
                new Organization {
                    Id = 2, Deleted = true
                },
                new Organization {
                    Id = 3
                }
            };
            var organizations = MockHelper.MockDbSet(organizationsTestData);

            var dbContext = new Mock <IAppDbContext>();

            dbContext.Setup(m => m.Organizations).Returns(organizations.Object);
            dbContext.Setup(d => d.Set <Organization>()).Returns(organizations.Object);

            dbContext.Setup(m => m.OrganizationAddresses).Returns(addresses.Object);
            dbContext.Setup(d => d.Set <OrganizationAddress>()).Returns(addresses.Object);

            dbContext.Setup(m => m.OrganizationContactPersons).Returns(contactPersons.Object);
            dbContext.Setup(d => d.Set <OrganizationContactPerson>()).Returns(contactPersons.Object);

            dbContext.Setup(m => m.OrganizationContactPersonContacts).Returns(contacts.Object);
            dbContext.Setup(d => d.Set <OrganizationContactPersonContact>()).Returns(contacts.Object);

            dbContext.Setup(m => m.OrganizationGTILinks).Returns(links.Object);
            dbContext.Setup(d => d.Set <OrganizationGTILink>()).Returns(links.Object);

            dbContext.Setup(m => m.GTIOrganizations).Returns(orgs.Object);
            dbContext.Setup(d => d.Set <OrganizationGTI>()).Returns(orgs.Object);

            dbContext.Setup(m => m.Offices).Returns(offices.Object);
            dbContext.Setup(d => d.Set <Office>()).Returns(offices.Object);

            dbContext.Setup(m => m.OrganizationProperties).Returns(properties.Object);
            dbContext.Setup(d => d.Set <OrganizationProperty>()).Returns(properties.Object);

            dbContext.Setup(m => m.OrganizationTaxAddresses).Returns(taxAddresses.Object);
            dbContext.Setup(d => d.Set <OrganizationTaxAddress>()).Returns(taxAddresses.Object);

            dbContext.Setup(m => m.OrganizationLanguageNames).Returns(names.Object);
            dbContext.Setup(d => d.Set <OrganizationLanguageName>()).Returns(names.Object);

            dbContext.Setup(m => m.OrganizationContactPersonViews).Returns(cpViews.Object);
            dbContext.Setup(d => d.Set <OrganizationContactPersonView>()).Returns(cpViews.Object);

            var factory = new Mock <IDbContextFactory>();

            factory.Setup(m => m.CreateDbContext()).Returns(dbContext.Object);
            var controller = new OrganizationsController(factory.Object);
            var result     = controller.GetOrganizationView(2) as OkNegotiatedContentResult <OrganizationDTO>;

            Assert.IsNotNull(result);
        }