示例#1
0
        public void SetUp()
        {
            var entry = new EntryModel(
                new ResourceBuilder()
                .WithLink("/rels/domestic/switches /rels/bookmark", "start-switch-uri")
                .Build());

            _startSwitchResource = new ResourceBuilder()
                                   .WithDataTemplate()
                                   .WithGroup("supplyPostcode")
                                   .WithItem("postcode")
                                   .WithGroup("references")
                                   .WithItem("partnerReference")
                                   .WithItem("apiKey")
                                   .Build();

            var configuration = Substitute.For <IConfiguration>();

            configuration.GetValue <string>("ApiEntryPoint").Returns("test-entry-point");

            _startSwitch = new StartSwitchModel(_startSwitchResource, configuration);
            _modelSaver  = Substitute.For <ISaveModel>();

            var modelLoader = Substitute.For <ILoadModel>();

            modelLoader.Load <Resource, EntryModel>("test-entry-point").Returns(entry);
            modelLoader.Load <Resource, StartSwitchModel>("start-switch-uri").Returns(_startSwitch);

            _controller = new HomeController(modelLoader, _modelSaver, configuration);
        }
        public void Posts_postcode_to_the_api(string groupName, string itemName, string expected)
        {
            var resource =
                new ResourceBuilder()
                .WithDataTemplate()
                .WithGroup("supplyPostcode")
                .WithItem("postcode")
                .WithGroup("references")
                .WithItem("partnerReference")
                .WithItem("apiKey")
                .Build();

            var configuration = Substitute.For <IConfiguration>();

            configuration.GetValue <string>("ApiKey").Returns("test-api-key");
            configuration.GetValue <string>("ApiPartnerReference").Returns("test-api-refence");

            var startSwitch = new StartSwitchModel(resource, configuration);

            startSwitch.Update("post-code");

            Assert.That(resource.DataTemplate.GetItem(groupName, itemName).Data, Is.EqualTo(expected));
        }