예제 #1
0
        public void HandleAsync_GivenSchemeWithOrganisationIdNotFound_ArgumentExceptionExpected_AndEmailMustNotBeSent()
        {
            // Arrange
            var schemeData = new SchemeData
            {
                OrganisationId = Guid.NewGuid()
            };

            var request          = new UpdateSchemeContactDetails(schemeData);
            var authorization    = A.Dummy <IWeeeAuthorization>();
            var dataAccess       = A.Fake <IOrganisationDetailsDataAccess>();
            var weeeEmailService = A.Dummy <IWeeeEmailService>();

            var scheme = A.Dummy <Scheme>();

            A.CallTo(() => dataAccess.FetchSchemeAsync(schemeData.OrganisationId)).Returns((Scheme)null);

            var handler = new UpdateSchemeContactDetailsHandler(authorization, dataAccess, weeeEmailService);

            // Act
            Func <Task> action = async() => await handler.HandleAsync(request);

            // Assert
            A.CallTo(() => weeeEmailService.SendOrganisationContactDetailsChanged(A <string> ._, A <string> ._, A <EntityType> ._))
            .MustNotHaveHappened();
            action.Should().Throw <ArgumentException>();
        }
예제 #2
0
        public async Task <ActionResult> ManageContactDetails(ManageContactDetailsViewModel model)
        {
            await SetBreadcrumb(model.SchemeId, InternalUserActivity.ManageScheme);

            if (!ModelState.IsValid)
            {
                using (var client = apiClient())
                {
                    model.OrganisationAddress.Countries = await client.SendAsync(User.GetAccessToken(), new GetCountries(false));
                }
                return(View(model));
            }

            using (var client = apiClient())
            {
                var orgData = new SchemeData()
                {
                    OrganisationId = model.OrgId,
                    Contact        = model.Contact,
                    Address        = model.OrganisationAddress,
                };
                await client.SendAsync(User.GetAccessToken(), new UpdateSchemeContactDetails(orgData));
            }

            return(RedirectToAction("Overview", new { schemeId = model.SchemeId, overviewDisplayOption = OverviewDisplayOption.ContactDetails }));
        }
예제 #3
0
        public async void GetSchemeByIdHandler_WithNonInternalUser_ThrowsSecurityException(AuthorizationBuilder.UserType userType)
        {
            // Arrage
            Guid schemeId = new Guid("AC9116BC-5732-4F80-9AED-A6E2A0C4C1F1");

            ISchemeDataAccess dataAccess = A.Fake <ISchemeDataAccess>();
            Scheme            scheme     = A.Fake <Scheme>();

            A.CallTo(() => dataAccess.GetSchemeOrDefault(schemeId)).Returns(scheme);

            IWeeeAuthorization authorization = AuthorizationBuilder.CreateFromUserType(userType);

            var        mapper     = A.Fake <IMapper>();
            SchemeData schemeData = A.Fake <SchemeData>();

            A.CallTo(() => mapper.Map <Scheme, SchemeData>(scheme))
            .Returns(schemeData);

            GetSchemeByIdHandler handler = new GetSchemeByIdHandler(dataAccess, mapper, authorization);

            GetSchemeById request = new GetSchemeById(schemeId);

            // Act
            Func <Task <SchemeData> > action = () => handler.HandleAsync(request);

            // Assert
            await Assert.ThrowsAsync <SecurityException>(action);
        }
예제 #4
0
        public async Task HandleAsync_WithContactDetailsChange_SendNotificationTrue_SendsChangeEmail()
        {
            // Arrange
            var authorization    = A.Dummy <IWeeeAuthorization>();
            var dataAccess       = A.Fake <IOrganisationDetailsDataAccess>();
            var weeeEmailService = A.Dummy <IWeeeEmailService>();

            var handler = new UpdateSchemeContactDetailsHandler(authorization, dataAccess, weeeEmailService);

            var contact = new Contact("FirstName", "LastName", "Position");

            var countryId     = Guid.NewGuid();
            var country       = new Country(countryId, "Country");
            var schemeAddress = new Address("Address1", "Address2", "TownOrCity",
                                            "CountyOrRegion", "Postcode", country, "Telephone", "Email");

            var scheme = A.Fake <Scheme>();

            A.CallTo(() => scheme.Contact).Returns(contact);
            A.CallTo(() => scheme.Address).Returns(schemeAddress);
            A.CallTo(() => scheme.SchemeName).Returns("SchemeName");
            A.CallTo(() => scheme.CompetentAuthority).Returns(new UKCompetentAuthority(Guid.NewGuid(), "name", "abb", country, "Email", null));

            A.CallTo(() => dataAccess.FetchSchemeAsync(A <Guid> ._)).Returns(scheme);
            A.CallTo(() => dataAccess.FetchCountryAsync(countryId)).Returns(country);

            var newContactDetails = new ContactData
            {
                FirstName = "New FirstName",
                LastName  = "New LastName",
                Position  = "New Position"
            };

            var newSchemeAddress = new AddressData
            {
                Address1       = "Address1",
                Address2       = "Address2",
                CountryId      = countryId,
                CountyOrRegion = "CountyOrRegion",
                Email          = "Email",
                Postcode       = "Postcode",
                Telephone      = "Telephone",
                TownOrCity     = "TownOrCity"
            };

            var organisationData = new SchemeData()
            {
                Contact = newContactDetails,
                Address = newSchemeAddress
            };

            var request = new UpdateSchemeContactDetails(organisationData, true);

            // Act
            await handler.HandleAsync(request);

            // Assert
            A.CallTo(() => weeeEmailService.SendOrganisationContactDetailsChanged("Email", "SchemeName", EntityType.Pcs))
            .MustHaveHappened();
        }
    /// <summary>
    /// 切换方案
    /// 由于自动打包会调用这里,所以将切换宏定义的代码也放在此处,注意!
    /// </summary>
    /// <param name="SchemeName"></param>
    public static void ChangeScheme(string SchemeName)
    {
        SchemeData data          = SDKManager.LoadGameSchemeConfig();
        string     oldSchemeName = "None";

        Debug.Log("ChangeScheme " + SchemeName);

        if (!IsExitsSchemeName(SchemeName))
        {
            Debug.Log("->" + SchemeName + "<- 方案不存在! ");
            return;
        }

        if (data != null)
        {
            oldSchemeName = data.SchemeName;
        }

        //方案相同不切换
        if (SchemeName == oldSchemeName)
        {
            return;
        }

        //重新生成游戏内使用的配置
        SaveGameSchemeConfig(GetSchemeData(SchemeName));
        AssetDatabase.Refresh();
    }
예제 #6
0
 void ChangeScheme(string newScheme, string oldScheme)
 {
     SchemeDataService.ChangeScheme(newScheme);
     m_currentSchemeData  = SDKManager.LoadGameSchemeConfig();
     m_currentSelectIndex = GetCurrentSelectIndex();
     LoadSchemeData(m_currentSchemeData);
 }
예제 #7
0
    //获取所有的方案
    void LoadSchemeConfig()
    {
        m_configList     = new List <SchemeData>();
        m_configNameList = new List <string>();

        Dictionary <string, object> editConfig = ConfigEditorWindow.GetEditorConfigData(s_editorConfigName);

        if (editConfig != null)
        {
            string currentSchemeName = editConfig[s_currentSchemeKey].ToString();

            List <object> list = (List <object>)editConfig[s_schemeKey];

            for (int i = 0; i < list.Count; i++)
            {
                SchemeData tmp = JsonUtility.FromJson <SchemeData>(list[i].ToString());
                if (tmp.SchemeName == currentSchemeName)
                {
                    currentSchemeData = tmp;
                    LoadCurrentSchemeConfig(tmp);
                }
                m_configList.Add(tmp);
                m_configNameList.Add(tmp.SchemeName);
            }
        }
    }
예제 #8
0
        public async void GetSchemeByIdHandler_HappyPath_ReturnsSchemeData()
        {
            // Arrage
            Guid schemeId = new Guid("AC9116BC-5732-4F80-9AED-A6E2A0C4C1F1");

            ISchemeDataAccess dataAccess = A.Fake <ISchemeDataAccess>();
            Scheme            scheme     = A.Fake <Scheme>();

            A.CallTo(() => dataAccess.GetSchemeOrDefault(schemeId)).Returns(scheme);

            IWeeeAuthorization authorization = new AuthorizationBuilder()
                                               .AllowInternalAreaAccess()
                                               .Build();

            var        mapper     = A.Fake <IMapper>();
            SchemeData schemeData = A.Fake <SchemeData>();

            A.CallTo(() => mapper.Map <Scheme, SchemeData>(scheme))
            .Returns(schemeData);

            GetSchemeByIdHandler handler = new GetSchemeByIdHandler(dataAccess, mapper, authorization);

            GetSchemeById request = new GetSchemeById(schemeId);

            // Act
            SchemeData result = await handler.HandleAsync(request);

            // Assert
            Assert.Equal(schemeData, result);
        }
예제 #9
0
        public async Task HandleAsync_WithValidData_FetchesSchemeAndUpdatesAndSaves()
        {
            // Arrange
            var schemeData = new SchemeData
            {
                Id             = Guid.NewGuid(),
                OrganisationId = Guid.NewGuid(),
                Contact        = new ContactData {
                    FirstName = "FirstName", LastName = "LastName", Position = "Position"
                },
                Address = new Core.Shared.AddressData
                {
                    Address1       = "Address1",
                    Address2       = "Address2",
                    TownOrCity     = "Town",
                    CountyOrRegion = "County",
                    Postcode       = "Postcode",
                    CountryId      = Guid.NewGuid(),
                    Telephone      = "012345678",
                    Email          = "*****@*****.**"
                }
            };

            var request          = new UpdateSchemeContactDetails(schemeData);
            var authorization    = A.Dummy <IWeeeAuthorization>();
            var dataAccess       = A.Fake <IOrganisationDetailsDataAccess>();
            var weeeEmailService = A.Dummy <IWeeeEmailService>();

            var scheme = A.Dummy <Scheme>();

            A.CallTo(() => dataAccess.FetchSchemeAsync(schemeData.OrganisationId)).Returns(scheme);

            var country = new Country(schemeData.Address.CountryId, "Name");

            A.CallTo(() => dataAccess.FetchCountryAsync(schemeData.Address.CountryId)).Returns(country);

            var handler =
                new UpdateSchemeContactDetailsHandler(authorization, dataAccess, weeeEmailService);

            // Act
            var result = await handler.HandleAsync(request);

            // Assert
            A.CallTo(() => dataAccess.FetchSchemeAsync(schemeData.OrganisationId)).MustHaveHappened(Repeated.Exactly.Once);

            Assert.Equal("FirstName", scheme.Contact.FirstName);
            Assert.Equal("LastName", scheme.Contact.LastName);
            Assert.Equal("Position", scheme.Contact.Position);
            Assert.Equal("Address1", scheme.Address.Address1);
            Assert.Equal("Address2", scheme.Address.Address2);
            Assert.Equal("Town", scheme.Address.TownOrCity);
            Assert.Equal("County", scheme.Address.CountyOrRegion);
            Assert.Equal("Postcode", scheme.Address.Postcode);
            Assert.Equal(schemeData.Address.CountryId, scheme.Address.Country.Id);
            Assert.Equal("012345678", scheme.Address.Telephone);
            Assert.Equal("*****@*****.**", scheme.Address.Email);

            A.CallTo(() => dataAccess.SaveAsync()).MustHaveHappened(Repeated.Exactly.Once);
        }
예제 #10
0
    /// <summary>
    /// 切换方案
    /// 由于自动打包会调用这里,所以将切换宏定义的代码也放在此处,注意!
    /// </summary>
    /// <param name="SchemeName"></param>
    public static void ChangeScheme(string SchemeName)
    {
        SchemeData data          = SDKManager.LoadGameSchemeConfig();
        string     oldSchemeName = "None";

        if (!IsExitsSchemeName(SchemeName))
        {
            Debug.Log("->" + SchemeName + "<- 方案不存在! ");
            return;
        }

        if (data != null)
        {
            oldSchemeName = data.SchemeName;
        }

        //方案相同不切换
        if (SchemeName == oldSchemeName)
        {
            return;
        }

        //重新生成游戏内使用的配置
        SaveGameSchemeConfig(GetSchemeData(SchemeName));

        if (IsExitsSchemeName(SchemeName))
        {
            Debug.Log("Index: " + GetSchemeIndex(SchemeName));

            //替换文件夹
            if (oldSchemeName != "None")
            {
                UnloadPluginFile(oldSchemeName);
                UnloadSchemeFile(oldSchemeName);
            }
            LoadPluginFile(SchemeName);
            LoadSchemeFile(SchemeName);

            //调整宏定义
            EditorExpand.ChangeDefine(new string[] { SchemeName }, new string[] { oldSchemeName });
        }
        else
        {
            //这部分代码实际上不会执行

            Debug.Log("不存在的方案名! " + SchemeName);
            if (oldSchemeName != "None")
            {
                //把当前方案收起来
                UnloadPluginFile(oldSchemeName);
                UnloadSchemeFile(oldSchemeName);

                //移除宏定义
                EditorExpand.ChangeDefine(new string[] {}, new string[] { oldSchemeName });
            }
        }

        AssetDatabase.Refresh();
    }
예제 #11
0
 public ViewFriendSchemeAction(SchemeData schemeData) : base(schemeData)
 {
     GetLong(StartIndex, out AccountId);
     if (!GetShort(StartIndex + 1, out KeyIndex))
     {
         KeyIndex = -1;
     }
 }
예제 #12
0
    void OnProjectChange()
    {
        SchemeDataService.ReloadEditorSchemeData();
        m_currentSchemeData  = SDKManager.LoadGameSchemeConfig();
        m_currentSelectIndex = GetCurrentSelectIndex();
        LoadSchemeData(m_currentSchemeData);

        CreateReadMe();
    }
예제 #13
0
    void OnEnable()
    {
        ResourcesConfigManager.Initialize();
        EditorGUIStyleData.Init();
        m_currentSchemeData  = SDKManager.LoadGameSchemeConfig();
        m_currentSelectIndex = GetCurrentSelectIndex();

        CreateReadMe();
    }
        public async Task HandleAsync_GivenGetSchemeExternalRequest_ReturnsSchemesSortedBySchemeNameAsync()
        {
            var request = new GetSchemesExternal();

            Organisation organisation = Organisation.CreateSoleTrader("Test Organisation");
            Scheme       scheme1      = new Scheme(organisation);

            scheme1.UpdateScheme("Scheme D", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy <UKCompetentAuthority>());
            scheme1.SetStatus(SchemeStatus.Approved);

            Scheme scheme2 = new Scheme(organisation);

            scheme2.UpdateScheme("Scheme A", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy <UKCompetentAuthority>());
            scheme2.SetStatus(SchemeStatus.Approved);

            Scheme scheme3 = new Scheme(organisation);

            scheme3.UpdateScheme("Scheme C", "WEE/11AAAA11/SCH", "WEE1234567", ObligationType.Both, A.Dummy <UKCompetentAuthority>());
            scheme3.SetStatus(SchemeStatus.Approved);

            var results = new List <Domain.Scheme.Scheme>()
            {
                scheme1,
                scheme2,
                scheme3
            };

            A.CallTo(() => dataAccess.GetCompleteSchemes()).Returns(results);

            IMap <Scheme, SchemeData> schemeMap = A.Fake <IMap <EA.Weee.Domain.Scheme.Scheme, SchemeData> >();

            schemeData1              = A.Fake <SchemeData>();
            schemeData1.SchemeName   = "Scheme D";
            schemeData1.SchemeStatus = Core.Shared.SchemeStatus.Approved;
            A.CallTo(() => schemeMap.Map(scheme1)).Returns(schemeData1);

            schemeData2              = A.Fake <SchemeData>();
            schemeData2.SchemeName   = "Scheme A";
            schemeData2.SchemeStatus = Core.Shared.SchemeStatus.Approved;
            A.CallTo(() => schemeMap.Map(scheme2)).Returns(schemeData2);

            schemeData3              = A.Fake <SchemeData>();
            schemeData3.SchemeName   = "Scheme C";
            schemeData3.SchemeStatus = Core.Shared.SchemeStatus.Approved;
            A.CallTo(() => schemeMap.Map(scheme3)).Returns(schemeData3);

            handler = new GetSchemesExternalHandler(dataAccess, schemeMap, authorization);

            var result = await handler.HandleAsync(request);

            Assert.Collection(
                result,
                (element1) => Assert.Equal("Scheme A", element1.SchemeName),
                (element2) => Assert.Equal("Scheme C", element2.SchemeName),
                (element3) => Assert.Equal("Scheme D", element3.SchemeName));
        }
예제 #15
0
    void DelectScheme()
    {
        SchemeDataService.DelectScheme(m_currentSchemeData);

        //移除宏定义
        EditorExpand.ChangeDefine(new string[] { }, new string[] { m_currentSchemeData.SchemeName });

        m_currentSchemeData  = null;
        m_currentSelectIndex = GetCurrentSelectIndex();
    }
예제 #16
0
        public AatfSchemeData(SchemeData scheme, ObligatedCategoryValue received, string approvalName)
        {
            Guard.ArgumentNotNull(() => scheme, scheme);
            Guard.ArgumentNotNull(() => received, received);

            Scheme   = scheme;
            Received = received;

            ApprovalName = approvalName;
        }
예제 #17
0
 void LoadSchemeData(SchemeData data)
 {
     SDKManager.AnalyzeSchemeData(data,
                                  out m_LoginScheme,
                                  out m_ADScheme,
                                  out m_PayScheme,
                                  out m_LogScheme,
                                  out m_otherScheme
                                  );
 }
예제 #18
0
        public void SchemeNameDisplay_GivenEmptySchemeNameIsNull_SchemeNameDisplayShouldBeCorrect()
        {
            var status = fixture.Create <SchemeStatus>();

            var model = new SchemeData()
            {
                SchemeStatus = status
            };

            model.SchemeNameDisplay.Should().Be($"Empty name ({status})");
        }
예제 #19
0
    void OnEnable()
    {
        //ResourcesConfigManager.Initialize();
        EditorGUIStyleData.Init();
        SchemeDataService.ReloadEditorSchemeData();
        m_currentSchemeData  = SDKManager.LoadGameSchemeConfig();
        m_currentSelectIndex = GetCurrentSelectIndex();
        LoadSchemeData(m_currentSchemeData);

        CreateReadMe();
    }
예제 #20
0
    void CreateScheme(string SchemeName)
    {
        SchemeData data = new SchemeData();

        data.SchemeName = SchemeName;

        SchemeDataService.ConfigList.Add(data);
        SchemeDataService.ConfigNameList.Add(data.SchemeName);

        configName = "";
        SchemeDataService.SaveEditorSchemeData();
    }
예제 #21
0
    /// <summary>
    /// 新增方案
    /// </summary>
    /// <param name="name"></param>
    /// <returns></returns>
    public static SchemeData AddScheme(string name)
    {
        SchemeData data = new SchemeData();

        data.SchemeName = name;

        ConfigList.Add(data);
        ConfigNameList.Add(data.SchemeName);
        SaveEditorSchemeData();

        return(data);
    }
        public override async Task OnAuthorizationAsync(ActionExecutingContext filterContext, Guid organisationId)
        {
            using (var client = Client())
            {
                SchemeData schemeData = await client.SendAsync(filterContext.HttpContext.User.GetAccessToken(), new GetSchemeByOrganisationId(organisationId));

                if (schemeData != null)
                {
                    filterContext.Result = new RedirectResult("~/admin/scheme/manage-schemes");
                }
            }
        }
예제 #23
0
 void DelectSchemeGUI()
 {
     if (GUILayout.Button("删除当前方案"))
     {
         if (EditorUtility.DisplayDialog("警告", "删除方案会删除对应的插件文件夹\n要继续吗?", "是", "取消"))
         {
             SchemeDataService.DelectScheme(m_currentSchemeData);
             m_currentSchemeData  = null;
             m_currentSelectIndex = GetCurrentSelectIndex();
         }
     }
 }
        public async Task HandleAsync_GivenSchemeNotFound_ArgumentExceptionExpected()
        {
            var request = new GetSchemeByOrganisationId(Guid.NewGuid());

            A.CallTo(() => dataAccess.GetSchemeOrDefaultByOrganisationId(request.OrganisationId)).Returns((Scheme)null);

            SchemeData result = await handler.HandleAsync(request);

            Assert.Null(result);

            A.CallTo(() => mapper.Map <Scheme, SchemeData>(A <Scheme> ._)).MustNotHaveHappened();
        }
 /// <summary>
 /// 将传入的SchemeData保存到游戏可以读取的地方
 /// </summary>
 /// <param name="schemeData"></param>
 public static void SaveGameSchemeConfig(SchemeData schemeData)
 {
     if (schemeData != null)
     {
         Dictionary <string, SingleField> config = new Dictionary <string, SingleField>();
         config.Add(SDKManager.c_KeyName, new SingleField(JsonUtility.ToJson(schemeData)));
         ConfigEditorWindow.SaveData(SDKManager.c_ConfigName, config);
     }
     else
     {
         File.Delete(ConfigEditorWindow.GetConfigPath(SDKManager.c_ConfigName));
     }
 }
예제 #26
0
        public async void OnActionExecuting_GivenOrganisationHasNoScheme_ContextResultShouldBeNull()
        {
            SchemeData schemeData = null;

            Guid organisationId = (Guid)context.ActionParameters["organisationId"];

            A.CallTo(() => client.SendAsync(A <string> ._,
                                            A <GetSchemeByOrganisationId> .That.Matches(r => r.OrganisationId.Equals(organisationId)))).Returns(schemeData);

            await attribute.OnAuthorizationAsync(context, organisationId);

            context.Result.Should().BeNull();
        }
        public async Task HandleAsync_GivenSchemeFound_SchemeDataShouldBeReturned()
        {
            var scheme     = A.Fake <Scheme>();
            var request    = new GetSchemeByOrganisationId(Guid.NewGuid());
            var schemeData = new SchemeData();

            A.CallTo(() => dataAccess.GetSchemeOrDefaultByOrganisationId(request.OrganisationId)).Returns(scheme);
            A.CallTo(() => mapper.Map <Scheme, SchemeData>(scheme)).Returns(schemeData);

            var result = await handler.HandleAsync(request);

            result.Should().Be(schemeData);
        }
예제 #28
0
    public static void AnalyzeSchemeData(
        SchemeData schemeData,

        out List <LoginInterface> loginScheme,
        out List <ADInterface> ADScheme,
        out List <PayInterface> payScheme,
        out List <LogInterface> logScheme,
        out List <OtherSDKInterface> otherScheme
        )
    {
        if (schemeData != null)
        {
            loginScheme = new List <LoginInterface>();
            for (int i = 0; i < schemeData.LoginScheme.Count; i++)
            {
                loginScheme.Add((LoginInterface)AnalysisConfig(schemeData.LoginScheme[i]));
            }

            ADScheme = new List <ADInterface>();
            for (int i = 0; i < schemeData.ADScheme.Count; i++)
            {
                ADScheme.Add((ADInterface)AnalysisConfig(schemeData.ADScheme[i]));
            }

            payScheme = new List <PayInterface>();
            for (int i = 0; i < schemeData.PayScheme.Count; i++)
            {
                payScheme.Add((PayInterface)AnalysisConfig(schemeData.PayScheme[i]));
            }

            logScheme = new List <LogInterface>();
            for (int i = 0; i < schemeData.LogScheme.Count; i++)
            {
                logScheme.Add((LogInterface)AnalysisConfig(schemeData.LogScheme[i]));
            }

            otherScheme = new List <OtherSDKInterface>();
            for (int i = 0; i < schemeData.OtherScheme.Count; i++)
            {
                otherScheme.Add((OtherSDKInterface)AnalysisConfig(schemeData.OtherScheme[i]));
            }
        }
        else
        {
            loginScheme = new List <LoginInterface>();
            ADScheme    = new List <ADInterface>();
            payScheme   = new List <PayInterface>();
            logScheme   = new List <LogInterface>();
            otherScheme = new List <OtherSDKInterface>();
        }
    }
예제 #29
0
        public AuthorizeServiceSchemeAction(SchemeData schemeData) : base(schemeData)
        {
            GetInt(StartIndex, out ChainId);
            var key = GetString(StartIndex + 1);

            try
            {
                if (key != null)
                {
                    ChainKey = Key.Restore(key);
                }
            }
            catch { }
        }
예제 #30
0
        public async void OnActionExecuting_GivenOrganisationHasAScheme_ShouldBeRedirectedToManageSchemes()
        {
            SchemeData schemeData = new SchemeData();

            Guid organisationId = (Guid)context.ActionParameters["organisationId"];

            A.CallTo(() => client.SendAsync(A <string> ._,
                                            A <GetSchemeByOrganisationId> .That.Matches(r => r.OrganisationId.Equals(organisationId)))).Returns(schemeData);

            await attribute.OnAuthorizationAsync(context, organisationId);

            RedirectResult result = context.Result as RedirectResult;

            result.Url.Should().Be("~/admin/scheme/manage-schemes");
        }
        private IMap<Scheme, SchemeData> CreateFakeSchemeMap()
        {
            IMap<Scheme, SchemeData> schemeMap = A.Fake<IMap<EA.Weee.Domain.Scheme.Scheme, SchemeData>>();

            schemeData1 = A.Fake<SchemeData>();
            schemeData1.Name = "MCH";
            A.CallTo(() => schemeMap.Map(scheme1)).Returns(schemeData1);

            schemeData2 = A.Fake<SchemeData>();
            schemeData2.Name = "ARB";
            A.CallTo(() => schemeMap.Map(scheme2)).Returns(schemeData2);

            schemeData3 = A.Fake<SchemeData>();
            schemeData3.Name = "ZRS";
            A.CallTo(() => schemeMap.Map(scheme3)).Returns(schemeData3);

            return schemeMap;
        }
        public async Task PostProducerDetails_WithInvalidViewModel_ReturnsSchemeWeeeDataProducerDataViewModel()
        {
            // Arrange
            IWeeeClient weeeClient = A.Fake<IWeeeClient>();

            List<int> years = new List<int>() { 2001, 2002 };
            A.CallTo(() => weeeClient.SendAsync(A<string>._, A<GetMemberRegistrationsActiveComplianceYears>._)).Returns(years);

            UKCompetentAuthorityData authority1 = new UKCompetentAuthorityData()
            {
                Id = new Guid("EB44DAD0-6B47-47C1-9124-4BE91042E563"),
                Abbreviation = "AA1"
            };
            List<UKCompetentAuthorityData> authorities = new List<UKCompetentAuthorityData>() { authority1 };
            A.CallTo(() => weeeClient.SendAsync(A<string>._, A<GetUKCompetentAuthorities>._)).Returns(authorities);

            SchemeData scheme1 = new SchemeData()
            {
                Id = new Guid("0F638399-226F-4942-AEF1-E6BC7EB447D6"),
                SchemeName = "Test Scheme"
            };
            List<SchemeData> schemes = new List<SchemeData>() { scheme1 };
            A.CallTo(() => weeeClient.SendAsync(A<string>._, A<Weee.Requests.Admin.GetSchemes>._)).Returns(schemes);

            ReportsController controller = new ReportsController(
                () => weeeClient,
                A.Dummy<BreadcrumbService>());

            // Act
            controller.ModelState.AddModelError("Key", "Error");
            ActionResult result = await controller.ProducerDetails(A.Dummy<ReportsFilterViewModel>());

            // Assert
            ViewResult viewResult = result as ViewResult;
            Assert.NotNull(viewResult);
            Assert.True(string.IsNullOrEmpty(viewResult.ViewName) || viewResult.ViewName.ToLowerInvariant() == "producerdetails");

            ReportsFilterViewModel model = viewResult.Model as ReportsFilterViewModel;
            Assert.NotNull(model);

            Assert.Collection(model.ComplianceYears,
                y1 => Assert.Equal("2001", y1.Text),
                y2 => Assert.Equal("2002", y2.Text));

            Assert.Collection(model.AppropriateAuthorities,
                a1 => { Assert.Equal("EB44DAD0-6B47-47C1-9124-4BE91042E563", a1.Value, true); Assert.Equal("AA1", a1.Text); });

            Assert.Collection(model.SchemeNames,
                s1 => { Assert.Equal("0F638399-226F-4942-AEF1-E6BC7EB447D6", s1.Value, true); Assert.Equal("Test Scheme", s1.Text); });
        }
        public async Task GetDownloadProducerDetailsCsv_WithSchemeIdAndAuthorityId_ReturnsFileNameWithComplianceYearSchemeApprovalNumberAuthorityAbbreviationAndCurrentTime()
        {
            // Arrange
            IWeeeClient client = A.Fake<IWeeeClient>();

            CSVFileData file = new CSVFileData() { FileContent = "Content" };
            A.CallTo(() => client.SendAsync(A<string>._, A<GetMemberDetailsCsv>._))
                .Returns(file);

            SchemeData schemeData = new SchemeData() { ApprovalName = "WEE/AA1111AA/SCH" };
            A.CallTo(() => client.SendAsync(A<string>._, A<GetSchemeById>._))
                .WhenArgumentsMatch(a => a.Get<GetSchemeById>("request").SchemeId == new Guid("88DF333E-6B2B-4D72-B411-7D7024EAA5F5"))
                .Returns(schemeData);

            UKCompetentAuthorityData authorityData = new UKCompetentAuthorityData() { Abbreviation = "AA" };
            A.CallTo(() => client.SendAsync(A<string>._, A<GetUKCompetentAuthorityById>._))
                .WhenArgumentsMatch(a => a.Get<GetUKCompetentAuthorityById>("request").Id == new Guid("703839B3-A081-4491-92B7-FCF969067EA3"))
                .Returns(authorityData);

            ReportsController controller = new ReportsController(
                () => client,
                A.Dummy<BreadcrumbService>());

            // Act
            SystemTime.Freeze(new DateTime(2016, 12, 31, 23, 59, 58));
            ActionResult result = await controller.DownloadProducerDetailsCsv(
                2015,
                new Guid("88DF333E-6B2B-4D72-B411-7D7024EAA5F5"),
                new Guid("703839B3-A081-4491-92B7-FCF969067EA3"),
                false,
                false);
            SystemTime.Unfreeze();

            // Assert
            FileResult fileResult = result as FileResult;
            Assert.NotNull(fileResult);

            Assert.Equal("2015_WEEAA1111AASCH_AA_producerdetails_31122016_2359.csv", fileResult.FileDownloadName);
        }