Ejemplo n.º 1
0
 public void Get_Cognitive_Service(Region expectedRegion) => LucidTest
 .Act(() => expectedRegion.GetCognitiveService("key"))
 .Assert(service =>
 {
     service.ShouldNotBeNull();
     service.Region.ShouldBe(expectedRegion);
 });
Ejemplo n.º 2
0
 public void Build_HttpRequestAuthorizer() => LucidTest
 .Arrange(() => new ServiceCollection())
 .Act(services => services.AddB2CAuthorizationAndVerification(Get <IB2CConfig>()))
 .Assert(services => services
         .BuildServiceProvider()
         .GetService <IHttpRequestAuthorizer>()
         .ShouldNotBeNull());
Ejemplo n.º 3
0
        public void Create_Group_From_Resource() => LucidTest
        .DefineExpected(() =>
        {
            const string Name = "file", Extension = ".json", Namespace = "My.Namespace", FullName = Name + Extension;
            return(new
            {
                Extension,
                FullName,
                Name,
                Namespace,
                ResourcePath = Namespace + "." + FullName
            });
        })
        .Arrange(param => { _resources = new[] { param.ResourcePath }; })
        .Act(GetResourceGroups)
        .Assert((expected, groups) =>
        {
            groups.ShouldNotBeNull();
            groups.Count().ShouldBe(1);

            var group = groups.First();
            group.ShouldNotBeNull();
            group.FullName.ShouldBe(expected.FullName);
            group.Extension.ShouldBe(expected.Extension);
            group.Name.ShouldBe(expected.Name);

            group.Tree.ShouldNotBeNull();
            group.Tree.FullName.ShouldBe(expected.ResourcePath);
            group.Tree.Name.ShouldBe(expected.FullName);
            group.Tree.Namespace.ShouldBe(expected.Namespace);
        });
Ejemplo n.º 4
0
 public void Call_TextToSpeech_With_Default_Audio() => LucidTest
 .DefineExpected(new byte[] { 123 })
 .Arrange(data => Get <ITextToSpeechConverter>()
          .GetSpeechAudioAsync(Arg.Any <ICognitiveService>(), Arg.Any <string>(), Arg.Any <Voice>(), TtsAudios.Mp3.Audio16khz64kbitrateMono)
          .Returns(data))
 .Act(_ => GetService(Region.WestEurope, "").TextToSpeech(TtsVoices.All.First(), "").Result)
 .Assert((expectedData, data) => data.ShouldBe(expectedData));
 public void Get_The_Same_Provider_Instance(Region region) => LucidTest
 .Arrange(() => Get <AccessTokenProviderFactory>())
 .Act(factory => new
 {
     Provider1 = factory.GetProvider(region),
     Provider2 = factory.GetProvider(region)
 })
 .Assert(providers => providers.Provider1.ShouldBe(providers.Provider2));
Ejemplo n.º 6
0
 public void Expected_Xml() => LucidTest
 .Arrange(() => new Voice(ExpectedLocale, "", Gender.Female, VoiceName))
 .Act(voice => new SpeechSynthesisMarkupLanguage(voice, Text))
 .Assert(ssml =>
 {
     ssml.ToXml().ShouldBe(ExpectedXml);
     ssml.ToString().ShouldBe(ExpectedXml);
 });
 public void Get_Property_Value(string propertyName) => LucidTest
 .DefineExpected(() => "ExpectedValue")
 .Arrange(value => new
 {
     Name     = propertyName,
     Provider = (IValueProvider) new JsonValueProvider($"{{ \"{propertyName}\": \"{value}\" }}")
 })
 .Act(param => param.Provider.GetValue(param.Name))
 .Assert((expectedValue, value) => value.ShouldBe(expectedValue));
Ejemplo n.º 8
0
 public void Get_Token() => LucidTest
 .DefineExpected("expected-token")
 .Arrange(expectedToken => $"my-url{UrlTokenReader.AuthTokenPrefix}{expectedToken}")
 .Act(GetToken)
 .Assert((expectedToken, token) =>
 {
     var validToken = token as ValidUrlToken;
     validToken.ShouldNotBeNull("Token is not valid");
     validToken.RawToken.ShouldBe(expectedToken);
 });
 public void Pass_Resource_Content_To_JsonValueProvider() => LucidTest
 .DefineExpected("JSON")
 .Arrange(json =>
 {
     Get <IResourceReader>().GetResourceContext(null).ReturnsForAnyArgs(json);
 })
 .Act(() => { Get <ResourceValueProvider>().GetValue(null); })
 .Assert(expectedContent =>
         Get <IJsonValueProviderFactory>()
         .Received()
         .GetJsonValueProvider(expectedContent));
 public void Pass_Resource_Path_To_ResourceReader() => LucidTest
 .DefineExpected("path")
 .Arrange(path =>
 {
     Get <IResourceTree>().FullName.Returns(path);
 })
 .Act(() => { Get <ResourceValueProvider>().GetValue(null); })
 .Assert(expectedPath =>
         Get <IResourceReader>()
         .Received()
         .GetResourceContext(expectedPath));
Ejemplo n.º 11
0
 public void Build_All_Services() => LucidTest
 .Arrange(() => new ServiceCollection())
 .Act(services => services.AddB2CAuthorization(Get <IB2CConfig>()))
 .Assert(services =>
 {
     var provider = services.BuildServiceProvider();
     foreach (var service in services)
     {
         var obj = provider.GetService(service.ServiceType);
         obj.ShouldNotBeNull();
     }
 });
Ejemplo n.º 12
0
 public void AccessToken_From_AccessTokenProvider(Region region) => LucidTest
 .DefineExpected("expectedAccessToken")
 .Arrange(token =>
 {
     const string Key = "serviceKey";
     var provider     = Get <ICachedAccessTokenProvider>();
     provider.GetAccessTokenAsync(Key).Returns(token);
     Get <IAccessTokenProviderFactory>().GetProvider(region).Returns(provider);
     return(Key);
 })
 .Act(key => GetService(region, key).GetAccessTokenAsync().Result)
 .Assert((expectedToken, token) => token.ShouldBe(expectedToken));
        public void Return_Value_From_JsonValueProvider() => LucidTest
        .DefineExpected(() => "value")
        .Arrange(value =>
        {
            var valueProvider = Get <IValueProvider>();
            Get <IJsonValueProviderFactory>().GetJsonValueProvider(null).ReturnsForAnyArgs(valueProvider);

            const string Key = "key";
            valueProvider.GetValue(Key).Returns(value);
            return(Key);
        })
        .Act(key => Get <ResourceValueProvider>().GetValue(key))
        .Assert((expectedValue, value) => value.ShouldBe(expectedValue));
 public void Get_SubValue(string name1, string name2) => LucidTest
 .DefineExpected(() => "ExpectedValue")
 .Arrange(value =>
 {
     var json = $"{{ \"{name1}\": {{ \"{name2}\": \"{value}\" }} }}";
     return(new
     {
         Name = $"{name1}.{name2}",
         Provider = (IValueProvider) new JsonValueProvider(json)
     });
 })
 .Act(param => param.Provider.GetValue(param.Name))
 .Assert((expectedValue, value) => value.ShouldBe(expectedValue));
Ejemplo n.º 15
0
 public void Different_Files_In_Different_Groups() => LucidTest
 .DefineExpected(new
 {
     File1 = "Namespace.File1.json",
     File2 = "Namespace.File2.json"
 })
 .Arrange(param => { _resources = new[] { param.File1, param.File2 }; })
 .Act(GetResourceGroups)
 .Assert((expected, groups) =>
 {
     groups.Count().ShouldBe(2);
     groups.First().Tree.FullName.ShouldBe(expected.File1);
     groups.Skip(1).First().Tree.FullName.ShouldBe(expected.File2);
 });
 public void Use_TypePrefix_To_Get_Translation() => LucidTest
 .DefineExpected("value")
 .Arrange(value =>
 {
     const string Prefix = "Type.Prefix", Key = "Key";
     var lang            = Get <ILanguage>().Set(l => l.GetTranslation($"{Prefix}.{Key}").Returns(value));
     return(new
     {
         Key,
         TypedLanguage = new TypedLanguage(lang, Prefix)
     });
 })
 .Act(param => param.TypedLanguage.GetTranslation(param.Key))
 .Assert(ValuesAreTheSame);
Ejemplo n.º 17
0
 public void Exclusive_Roots() => LucidTest
 .DefineExpected(() => new
 {
     Root1 = "Some.Root.Resource.json",
     Root2 = "Other.Root.Resource.json"
 })
 .Arrange(item => new[] { item.Root1, item.Root2 })
 .Act(GetResourceTree)
 .Assert((expected, tree) =>
 {
     tree.Name.ShouldBe("");
     tree.Children.ShouldContain(t => t.FullName == expected.Root1);
     tree.Children.ShouldContain(t => t.FullName == expected.Root2);
 });
Ejemplo n.º 18
0
 public void Get_Broken_Token() => LucidTest
 .DefineExpected(new
 {
     Error       = "expected-error",
     Description = "Error description !@#$"
 })
 .Arrange(expected => $"my-url{UrlTokenReader.ErrorNamePrefix}{Uri.EscapeDataString(expected.Error)}{UrlTokenReader.ErrorDescriptionPrefix}{Uri.EscapeDataString(expected.Description)}")
 .Act(GetToken)
 .Assert((expected, token) =>
 {
     var brokenToken = token as BrokenUrlToken;
     brokenToken.ShouldNotBeNull();
     brokenToken.Error.ShouldBe(expected.Error);
     brokenToken.ErrorDescription.ShouldBe(expected.Description);
 });
Ejemplo n.º 19
0
        public void No_Value_When_Wrong_Namespace() => LucidTest
        .Arrange(() =>
        {
            const string Key  = "key";
            var valueProvider = Get <IValueProvider>();
            valueProvider.GetValue(Key).Returns("value");

            return(new
            {
                Key = $"Wrong.Namespace.{Key}",
                Provider = new NamespaceValueProvider("Correct.Namespace", valueProvider)
            });
        })
        .Act(param => param.Provider.GetValue(param.Key))
        .Assert(value => value.ShouldBeNull());
        public void Get_Value_When_Single_Provider() => LucidTest
        .DefineExpected("value")
        .Arrange(value =>
        {
            const string Key = "key";
            var provider     = Get <IValueProvider>();
            provider.GetValue(Key).Returns(value);

            return(new
            {
                Key,
                Provider = new CascadingValueProvider(provider)
            });
        })
        .Act(param => param.Provider.GetValue(param.Key))
        .Assert(ValuesAreTheSame);
Ejemplo n.º 21
0
        public void Get_Value_Without_Namespace(string namespaceName) => LucidTest
        .DefineExpected("value")
        .Arrange(value =>
        {
            var valueProvider = Get <IValueProvider>();

            const string Key = "name";
            valueProvider.GetValue(Key).Returns(value);

            return(new
            {
                Key,
                Provider = new NamespaceValueProvider(namespaceName, valueProvider)
            });
        })
        .Act(param => param.Provider.GetValue(param.Key))
        .Assert(ValuesAreTheSame);
Ejemplo n.º 22
0
        public void Get_Value_With_Namespace() => LucidTest
        .DefineExpected("value")
        .Arrange(value =>
        {
            const string Namespace = "Namespace", Key = "Key";

            var valueProvider = Get <IValueProvider>();
            valueProvider.GetValue(Key).Returns(value);

            return(new
            {
                Key = $"{Namespace}.{Key}",
                Provider = new NamespaceValueProvider(Namespace, valueProvider)
            });
        })
        .Act(param => param.Provider.GetValue(param.Key))
        .Assert(ValuesAreTheSame);
 public async Task Pass_Token_To_Factory() => await LucidTest
 .DefineExpected(() =>
 {
     var token = Get <ITokenInfo>();
     token.Expiration.Returns(DateTime.Now.AddDays(1));
     return(token);
 })
 .Arrange(token =>
 {
     const string TextToken = "SOME-TOKEN";
     Get <ITokenInfoFactory>()
     .GetTokenInfoAsync(null)
     .ReturnsForAnyArgs(ci => ci.Arg <ValidUrlToken>().RawToken == TextToken ? token : null);
     return(GenerateAuthorizationHeader("Bearer " + TextToken));
 })
 .ActAsync(GetTokenAsync)
 .AssertAsync((expectedToken, tokenInfo) => tokenInfo.ShouldBe(expectedToken));
Ejemplo n.º 24
0
 public void The_Same_File_In_Two_Places_Result_In_Single_Group() => LucidTest
 .DefineExpected(() =>
 {
     const string FileName = "file.json";
     return(new
     {
         FileName,
         Path1 = "Namespace." + FileName,
         Path2 = "Namespace.More." + FileName
     });
 })
 .Arrange(param => { _resources = new[] { param.Path1, param.Path2 }; })
 .Act(GetResourceGroups)
 .Assert((expected, groups) =>
 {
     groups.Count().ShouldBe(1);
     var group = groups.First();
     group.FullName.ShouldBe(expected.FileName);
     group.Tree.Children.Count().ShouldBe(1);
 });
Ejemplo n.º 25
0
 public void Root_With_Childs_Child() => LucidTest
 .DefineExpected(() =>
 {
     const string ParentNamespace = "Parent.Namespace.";
     var childNamespace           = $"{ParentNamespace}Child.";
     return(new
     {
         Parent = $"{ParentNamespace}Parent.json",
         Child = $"{childNamespace}Child.json",
         SubChild = $"{childNamespace}.SubChild.File.json"
     });
 })
 .Arrange(param => new[] { param.Parent, param.SubChild, param.Child })
 .Act(GetResourceTree)
 .Assert((expected, tree) =>
 {
     tree.FullName.ShouldBe(expected.Parent);
     tree.Children.First().FullName.ShouldBe(expected.Child);
     tree.Children.First().Children.First().FullName.ShouldBe(expected.SubChild);
 });
Ejemplo n.º 26
0
 public void Root_With_Children() => LucidTest
 .DefineExpected(() =>
 {
     const string ParentNamespace = "My.Parent.Namespace.";
     var childNamespace           = $"{ParentNamespace}SubName.";
     return(new
     {
         Parent = $"{ParentNamespace}Parent.json",
         Child1 = $"{childNamespace}Child1.json",
         Child2 = $"{childNamespace}Child2.json"
     });
 })
 .Arrange(param => new[] { param.Child1, param.Parent, param.Child2 })
 .Act(GetResourceTree)
 .Assert((expected, tree) =>
 {
     tree.FullName.ShouldBe(expected.Parent);
     tree.Children.ShouldContain(n => n.FullName == expected.Child1);
     tree.Children.ShouldContain(n => n.FullName == expected.Child2);
 });
Ejemplo n.º 27
0
        public void Call_TextToSpeech() => LucidTest
        .DefineExpected(new byte[] { 123 })
        .Arrange(data =>
        {
            const string Text = "some text";
            var audio         = TtsAudios.Wav.Riff16khz16bitMonoPcm;
            var voice         = TtsVoices.Standard.pl_PL_PaulinaRUS;

            Get <ITextToSpeechConverter>()
            .GetSpeechAudioAsync(Arg.Any <ICognitiveService>(), Text, voice, audio)
            .Returns(data);

            return(new
            {
                Audio = audio,
                Service = GetService(Region.WestEurope, ""),
                Text,
                Voice = voice
            });
        })
        .Act(param => param.Service.TextToSpeech(param.Voice, param.Text, param.Audio).Result)
        .Assert((expectedData, data) => data.ShouldBe(expectedData));
        public void Get_Value_When_Many_Providers(int providerCount) => LucidTest
        .DefineExpected("value")
        .Arrange(value =>
        {
            var providers = new List <IValueProvider>();
            for (int i = 1; i < providerCount; i++)
            {
                providers.Add(new JsonValueProvider("{ }"));
            }

            const string Key = "key";
            var provider     = Get <IValueProvider>();
            provider.GetValue(Key).Returns(value);
            providers.Add(provider);

            return(new
            {
                Key,
                Provider = new CascadingValueProvider(providers)
            });
        })
        .Act(param => param.Provider.GetValue(param.Key))
        .Assert(ValuesAreTheSame);
Ejemplo n.º 29
0
        public void Get_Value_From_Group_Value_Provider() => LucidTest
        .DefineExpected("value")
        .Arrange(code =>
        {
            var valueProvider = Get <IValueProvider>();
            const string Key  = "key";
            valueProvider.GetValue(Key).Returns(code);

            var asm       = GetType().Assembly;
            var group     = Get <IResourceGroup>();
            var converter = Get <IGroupConverter>();
            converter.ConvertToValueProvider(asm, group).Returns(valueProvider);

            return(new
            {
                Assembly = asm,
                Code = code,
                Converter = converter,
                Key
            });
        })
        .Act(param => GetLanguage(param.Assembly, GetGroup(param.Code), param.Converter).GetTranslation(param.Key))
        .Assert(ValuesAreTheSame);
Ejemplo n.º 30
0
 public void Return_Null_When_No_Token(string url) => LucidTest
 .Act(() => GetToken(url))
 .Assert(token => token.ShouldBeNull());