public void GivenInputWithRegisteredFactories_WhenCreate_ThenTemplateReturned_Test(string json)
        {
            IFhirTemplate nullReturn = null;

            var templateA = Substitute.For <IFhirTemplate>();

            templateA.TypeName.Returns("A");

            var templateB = Substitute.For <IFhirTemplate>();

            templateB.TypeName.Returns("B");

            var factoryA = Substitute.For <ITemplateFactory <TemplateContainer, IFhirTemplate> >();

            factoryA.Create(Arg.Is <TemplateContainer>(v => v.MatchTemplateName("mockA"))).Returns(templateA);
            factoryA.Create(Arg.Is <TemplateContainer>(v => !v.MatchTemplateName("mockA"))).Returns(nullReturn);

            var factoryB = Substitute.For <ITemplateFactory <TemplateContainer, IFhirTemplate> >();

            factoryB.Create(Arg.Is <TemplateContainer>(v => v.MatchTemplateName("mockB"))).Returns(templateB);
            factoryB.Create(Arg.Is <TemplateContainer>(v => !v.MatchTemplateName("mockB"))).Returns(nullReturn);

            var factory         = new CollectionFhirTemplateFactory(factoryA, factoryB);
            var templateContext = factory.Create(json);

            Assert.NotNull(templateContext);
            templateContext.EnsureValid();

            factoryA.ReceivedWithAnyArgs().Create(null);
            factoryB.ReceivedWithAnyArgs().Create(null);
        }
        public void GivenInputWithUnregisteredFactories_WhenCreate_ThenException_Test(string json)
        {
            IFhirTemplate nullReturn = null;
            var           templateA  = Substitute.For <IFhirTemplate>();

            templateA.TypeName.Returns("A");

            var templateC = Substitute.For <IFhirTemplate>();

            templateC.TypeName.Returns("C");

            var factoryA = Substitute.For <ITemplateFactory <TemplateContainer, IFhirTemplate> >();

            factoryA.Create(Arg.Is <TemplateContainer>(v => v.MatchTemplateName("mockA"))).Returns(templateA);
            factoryA.Create(Arg.Is <TemplateContainer>(v => !v.MatchTemplateName("mockA"))).Returns(nullReturn);

            var factoryC = Substitute.For <ITemplateFactory <TemplateContainer, IFhirTemplate> >();

            factoryC.Create(Arg.Is <TemplateContainer>(v => v.MatchTemplateName("mockC"))).Returns(templateC);
            factoryC.Create(Arg.Is <TemplateContainer>(v => !v.MatchTemplateName("mockC"))).Returns(nullReturn);

            var factory         = new CollectionFhirTemplateFactory(factoryA, factoryC);
            var templateContext = factory.Create(json);

            Assert.Throws <ValidationException>(() => templateContext.EnsureValid());
            Assert.False(templateContext.IsValid(out _));

            factoryA.ReceivedWithAnyArgs().Create(null);
            factoryC.ReceivedWithAnyArgs().Create(null);
        }