Ejemplo n.º 1
0
        public IEnumerator GetUserInfoAsync_JsonParseFailed_ReturnsNull()
        {
            LearningLayersOidcProvider lloidc        = new LearningLayersOidcProvider();
            IRestConnector             restConnector = A.Fake <IRestConnector>();

            A.CallTo(() => restConnector.GetAsync(A <string> .Ignored))
            .Returns(new WebResponse <string>("answer", null, 200));
            lloidc.RestConnector = restConnector;
            LearningLayersUserInfo userInfo   = new LearningLayersUserInfo("tester", "*****@*****.**", "Tester");
            IJsonSerializer        serializer = A.Fake <IJsonSerializer>();

            A.CallTo(() => serializer.FromJson <LearningLayersUserInfo>(A <string> .Ignored))
            .Returns(null);
            lloidc.JsonSerializer = serializer;

            LogAssert.Expect(LogType.Error, new Regex(@"\w*Could not parse user info\w*"));

            Task <IUserInfo> task = lloidc.GetUserInfoAsync("");

            yield return(AsyncTest.WaitForTask(task));

            IUserInfo res = task.Result;

            Assert.IsNull(res);
        }
Ejemplo n.º 2
0
        public IEnumerator GetAccessCodeFromTokenAsync_WebResponseSuccess_ReturnsToken()
        {
            LearningLayersOidcProvider lloidc        = new LearningLayersOidcProvider();
            IRestConnector             restConnector = A.Fake <IRestConnector>();

            A.CallTo(() => restConnector.PostAsync(A <string> .Ignored, A <string> .Ignored))
            .Returns(Task.FromResult(new WebResponse <string>("json string", null, 200)));
            lloidc.RestConnector = restConnector;
            lloidc.ClientData    = A.Fake <ClientData>();
            LearningLayersAuthorizationFlowAnswer answer = new LearningLayersAuthorizationFlowAnswer();

            answer.access_token = "myAccessToken";
            IJsonSerializer serializer = A.Fake <IJsonSerializer>();

            A.CallTo(() => serializer.FromJson <LearningLayersAuthorizationFlowAnswer>(A <string> .Ignored))
            .Returns(answer);
            lloidc.JsonSerializer = serializer;

            Task <string> task = lloidc.GetAccessTokenFromCodeAsync("", "");

            yield return(AsyncTest.WaitForTask(task));

            string res = task.Result;

            Assert.AreEqual(answer.access_token, res);
        }
Ejemplo n.º 3
0
        public IEnumerator ExtendedLogging_Disabled_CommentsNotLogged()
        {
            mtlLibrary.ContentLoader   = FakeContentLoaderFactory.CreateFakeLoader(content);
            mtlLibrary.ExtendedLogging = false;
            Task task = LoadLibrary();

            yield return(AsyncTest.WaitForTask(task));

            LogAssert.NoUnexpectedReceived();
        }
Ejemplo n.º 4
0
        public IEnumerator ExtendedLogging_Enabled_CommentsLogged()
        {
            mtlLibrary.ContentLoader   = FakeContentLoaderFactory.CreateFakeLoader(content);
            mtlLibrary.ExtendedLogging = true;
            Task task = LoadLibrary();

            yield return(AsyncTest.WaitForTask(task));

            LogAssert.Expect(LogType.Log, new Regex(@"\w*Comment found\w*"));
        }
Ejemplo n.º 5
0
        public IEnumerator LoadLibraryAsync_NewLibrary_LibraryLoadedReturnsTrue()
        {
            mtlLibrary.ContentLoader = FakeContentLoaderFactory.CreateFakeLoader(content);
            Task task = LoadLibrary();

            yield return(AsyncTest.WaitForTask(task));

            bool loaded = mtlLibrary.LibraryLoaded(libraryName);

            Assert.IsTrue(loaded, "The library should have been loaded but is not displayed as loaded");
        }
Ejemplo n.º 6
0
        public IEnumerator GetMaterialConstructor_ExistentMatLibExistentMat_ReturnsNotNull()
        {
            mtlLibrary.ContentLoader = FakeContentLoaderFactory.CreateFakeLoader(content);
            Task task = LoadLibrary();

            yield return(AsyncTest.WaitForTask(task));

            MaterialConstructor res = mtlLibrary.GetMaterialConstructor(libraryName, "BlueMat");

            Assert.IsNotNull(res);
        }
Ejemplo n.º 7
0
        public IEnumerator FetchDependencies_NoTexturesProvided_ReturnsTrue()
        {
            MaterialConstructor materialConstructor = new MaterialConstructor();
            Task <bool>         task = materialConstructor.FetchDependencies();

            yield return(AsyncTest.WaitForTask(task));

            bool success = task.Result;

            Assert.True(success);
        }
Ejemplo n.º 8
0
        public IEnumerator GetMaterialConstructor_ExistentMatLibExistentMat_MatConstrColorSet()
        {
            mtlLibrary.ContentLoader = FakeContentLoaderFactory.CreateFakeLoader(content);
            Task task = LoadLibrary();

            yield return(AsyncTest.WaitForTask(task));

            MaterialConstructor res = mtlLibrary.GetMaterialConstructor(libraryName, "BlueMat");

            Assert.IsNotNull(res);
            Assert.AreEqual(new Color(0.185991f, 0.249956f, 0.800000f), res.Color);
        }
Ejemplo n.º 9
0
        public IEnumerator ImportAsync_ThreeObj_HasThreeChildren()
        {
            ObjImporter objImporter = SetUpObjImporter(threeObj, threeMtl);

            Task <GameObject> task = objImporter.ImportAsync("http://test.org/test.obj");

            yield return(AsyncTest.WaitForTask(task));

            GameObject res = task.Result;

            Assert.AreEqual(3, res.transform.childCount);
        }
Ejemplo n.º 10
0
        public IEnumerator ImportAsync_WebRequestSuccess_SetName()
        {
            ObjImporter objImporter = SetUpObjImporter(cubeObj, cubeMtl);

            Task <GameObject> task = objImporter.ImportAsync("http://test.org/test.obj");

            yield return(AsyncTest.WaitForTask(task));

            GameObject res = task.Result;

            Assert.NotNull(res);
            Assert.AreEqual("test", res.name);
        }
Ejemplo n.º 11
0
        public IEnumerator ImportAsync_CubeObj_HasChild()
        {
            ObjImporter objImporter = SetUpObjImporter(cubeObj, cubeMtl);

            Task <GameObject> testTask = objImporter.ImportAsync("http://test.org/test.obj");

            yield return(AsyncTest.WaitForTask(testTask));

            GameObject res = testTask.Result;

            Assert.NotNull(res);
            Assert.AreEqual(1, res.transform.childCount);
        }
Ejemplo n.º 12
0
        public IEnumerator LoadLibraryAsync_LoadFailed_LibraryLoadedReturnsFalse()
        {
            mtlLibrary.ContentLoader = FakeContentLoaderFactory.CreateFakeFailLoader <string>();

            LogAssert.Expect(LogType.Error, new Regex(@"\w*This is a simulated fail\w*"));

            Task task = LoadLibrary();

            yield return(AsyncTest.WaitForTask(task));

            bool loaded = mtlLibrary.LibraryLoaded(libraryName);

            Assert.IsFalse(loaded, "The import should have aborted but apparently, the library is shown as imported");
        }
Ejemplo n.º 13
0
        public IEnumerator ImportAsync_CubeObj_ChildHasCorrectMaterial()
        {
            ObjImporter objImporter = SetUpObjImporter(cubeObj, cubeMtl);

            Task <GameObject> task = objImporter.ImportAsync("http://test.org/test.obj");

            yield return(AsyncTest.WaitForTask(task));

            GameObject res = task.Result;

            MeshRenderer mr = res.transform.GetChild(0).GetComponent <MeshRenderer>();

            Assert.AreEqual("TestMaterial", mr.sharedMaterial.name);
        }
Ejemplo n.º 14
0
        public IEnumerator ImportAsync_CubeObj_ChildHasCorrectMesh()
        {
            ObjImporter objImporter = SetUpObjImporter(cubeObj, cubeMtl);

            Task <GameObject> task = objImporter.ImportAsync("http://test.org/test.obj");

            yield return(AsyncTest.WaitForTask(task));

            GameObject res = task.Result;

            MeshFilter mf = res.transform.GetChild(0).GetComponent <MeshFilter>();

            Assert.AreEqual(24, mf.sharedMesh.vertices.Length);  // 8 * 3 = 24 (every vertex belongs to three triangles)
            Assert.AreEqual(36, mf.sharedMesh.triangles.Length); // 12 *3 = 36
        }
Ejemplo n.º 15
0
        public IEnumerator FetchDependencies_TextureFetchFail_ReturnsFalse()
        {
            MaterialConstructor materialConstructor        = new MaterialConstructor();
            ITextureConstructor fakeTextureConstructorFail = A.Fake <ITextureConstructor>();

            A.CallTo(() => fakeTextureConstructorFail.FetchTextureAsync()).Returns(Task.FromResult <Texture2D>(null));
            materialConstructor.SetTexture("tex", fakeTextureConstructorFail);

            Task <bool> task = materialConstructor.FetchDependencies();

            yield return(AsyncTest.WaitForTask(task));

            bool success = task.Result;

            Assert.False(success);
        }
Ejemplo n.º 16
0
        public IEnumerator FetchTextureAsync_WebRequestFailed_ReturnsNull()
        {
            TextureConstructor textureConstructor = new TextureConstructor(loadPath);

            textureConstructor.TextureLoader = FakeContentLoaderFactory.CreateFakeFailLoader <Texture2D>();

            LogAssert.Expect(LogType.Error, new Regex(@"\w*This is a simulated fail\w*"));

            Task <Texture2D> task = textureConstructor.FetchTextureAsync();

            yield return(AsyncTest.WaitForTask(task));

            Texture2D res = task.Result;

            Assert.Null(res);
        }
Ejemplo n.º 17
0
        public IEnumerator FetchTextureAsync_WebRequestSuccessful_ReturnsTexture()
        {
            TextureConstructor textureConstructor = new TextureConstructor(loadPath);
            Texture2D          expected           = new Texture2D(2, 2);

            textureConstructor.TextureLoader = FakeContentLoaderFactory.CreateFakeLoader(expected);

            Task <Texture2D> task = textureConstructor.FetchTextureAsync();

            yield return(AsyncTest.WaitForTask(task));

            Texture2D res = task.Result;

            Assert.NotNull(res);
            Assert.AreEqual(expected.imageContentsHash, res.imageContentsHash);
        }
Ejemplo n.º 18
0
        public IEnumerator ImportAsync_EmptyObj_ReturnGameObject()
        {
            ObjImporter objImporter = SetUpObjImporter(emptyObj, emptyMtl);

            LogAssert.Expect(LogType.Warning, new Regex(@"\w*There is an object without parsed vertices\w*"));
            LogAssert.Expect(LogType.Error, new Regex(@"\w*No objects could be constructed.\w*"));

            Task <GameObject> task = objImporter.ImportAsync("http://test.org/test.obj");

            yield return(AsyncTest.WaitForTask(task));

            GameObject res = task.Result;

            Assert.NotNull(res);
            Assert.AreEqual(0, res.transform.childCount);
        }
Ejemplo n.º 19
0
        public IEnumerator GetAccessCodeFromTokenAsync_NoClientData_ReturnsEmptyString()
        {
            LearningLayersOidcProvider lloidc = new LearningLayersOidcProvider();

            lloidc.RestConnector = A.Fake <IRestConnector>();

            LogAssert.Expect(LogType.Error,
                             new Regex(@"\w*No client data supplied for the OpenID Connect Client\w*"));

            Task <string> task = lloidc.GetAccessTokenFromCodeAsync("", "");

            yield return(AsyncTest.WaitForTask(task));

            string res = task.Result;

            Assert.IsEmpty(res);
        }
Ejemplo n.º 20
0
        public IEnumerator ImportAsync_CubeObj_ChildHasComponents()
        {
            ObjImporter objImporter = SetUpObjImporter(cubeObj, cubeMtl);

            Task <GameObject> task = objImporter.ImportAsync("http://test.org/test.obj");

            yield return(AsyncTest.WaitForTask(task));

            GameObject res = task.Result;

            MeshFilter mf = res.transform.GetChild(0).GetComponent <MeshFilter>();

            Assert.NotNull(mf);
            MeshRenderer mr = res.transform.GetChild(0).GetComponent <MeshRenderer>();

            Assert.NotNull(mr);
        }
Ejemplo n.º 21
0
        public IEnumerator ImportAsync_WebRequestFailed_ReturnNull()
        {
            ObjImporter     objImporter    = new ObjImporter();
            IServiceManager serviceManager = A.Fake <IServiceManager>();

            objImporter.Initialize(serviceManager);
            objImporter.ContentLoader = FakeContentLoaderFactory.CreateFakeFailLoader <string>();

            LogAssert.Expect(LogType.Error, new Regex(@"\w*Error fetching obj. No object imported\w*"));

            Task <GameObject> task = objImporter.ImportAsync("http://test.org/test.obj");

            yield return(AsyncTest.WaitForTask(task));

            GameObject res = task.Result;

            Assert.Null(res);
        }
Ejemplo n.º 22
0
        public IEnumerator LoadLibraryAsync_LoadLibraryMultipleTimes_NoErrorsAndLibraryLoadedTrue()
        {
            mtlLibrary.ContentLoader = FakeContentLoaderFactory.CreateFakeLoader(content);
            Task task = LoadLibrary();

            yield return(AsyncTest.WaitForTask(task));

            bool loaded = mtlLibrary.LibraryLoaded(libraryName);

            Assert.IsTrue(loaded, "The library should have been loaded but is not displayed as loaded");

            Task task2 = LoadLibrary();

            yield return(AsyncTest.WaitForTask(task2));

            LogAssert.Expect(LogType.Warning, new Regex(@"\w*was already loaded\w*"));
            loaded = mtlLibrary.LibraryLoaded(libraryName);
            Assert.IsTrue(loaded, "Loading the same library multiple times makes the library show up as unloaded");
        }
Ejemplo n.º 23
0
        public IEnumerator CheckAccessTokenAsync_WebResponseFailed_ReturnsFalse()
        {
            LearningLayersOidcProvider lloidc        = new LearningLayersOidcProvider();
            IRestConnector             restConnector = A.Fake <IRestConnector>();

            A.CallTo(() => restConnector.GetAsync(A <string> .Ignored))
            .Returns(new WebResponse <string>("This is a simulated error", 400));
            lloidc.RestConnector = restConnector;

            LogAssert.Expect(LogType.Error, new Regex(@"\w*This is a simulated error\w*"));

            Task <bool> task = lloidc.CheckAccessTokenAsync("");

            yield return(AsyncTest.WaitForTask(task));

            bool res = task.Result;

            Assert.IsFalse(res);
        }
Ejemplo n.º 24
0
        public IEnumerator ImportAsync_ObjFetchSuccessMtlFetchFail_CreateObjectWithDefaultMat()
        {
            ObjImporter objImporter = SetUpObjImporter(cubeObj, "");

            objImporter.MtlLibrary.ContentLoader = FakeContentLoaderFactory.CreateFakeFailLoader <string>();

            LogAssert.Expect(LogType.Error, new Regex(@"\w*This is a simulated fail\w*"));
            LogAssert.Expect(LogType.Error, new Regex(@"\w*Could not load .mtl file\w*"));

            Task <GameObject> task = objImporter.ImportAsync("http://test.org/test.obj");

            yield return(AsyncTest.WaitForTask(task));

            GameObject res = task.Result;

            Assert.NotNull(res);
            Assert.AreEqual(1, res.transform.childCount);
            MeshRenderer mr = res.transform.GetChild(0).GetComponent <MeshRenderer>();

            Assert.AreEqual("New Material", mr.sharedMaterial.name);
        }
Ejemplo n.º 25
0
        public IEnumerator ConstructMaterial_FetchedTexture_TextureSetInMaterial()
        {
            MaterialConstructor materialConstructor    = new MaterialConstructor();
            Texture2D           expectedTexture        = new Texture2D(2, 2);
            ITextureConstructor fakeTextureConstructor = A.Fake <ITextureConstructor>();

            A.CallTo(() => fakeTextureConstructor.FetchTextureAsync()).Returns(Task.FromResult(expectedTexture));
            materialConstructor.SetTexture("_MainTex", fakeTextureConstructor);
            Task <bool> task = materialConstructor.FetchDependencies();

            yield return(AsyncTest.WaitForTask(task));

            bool success = task.Result;

            Assert.True(success);

            Material mat = materialConstructor.ConstructMaterial();

            Assert.NotNull(mat.mainTexture);
            Assert.AreEqual(expectedTexture.imageContentsHash, mat.mainTexture.imageContentsHash);
        }
Ejemplo n.º 26
0
        public IEnumerator GetAccessCodeFromTokenAsync_WebResponseFailed_ReturnsEmptyToken()
        {
            LearningLayersOidcProvider lloidc        = new LearningLayersOidcProvider();
            IRestConnector             restConnector = A.Fake <IRestConnector>();

            A.CallTo(() => restConnector.PostAsync(A <string> .Ignored, A <string> .Ignored))
            .Returns(Task.FromResult(new WebResponse <string>("my error", 400)));
            lloidc.RestConnector  = restConnector;
            lloidc.ClientData     = A.Fake <ClientData>();
            lloidc.JsonSerializer = A.Fake <IJsonSerializer>();

            LogAssert.Expect(LogType.Error,
                             new Regex(@"\w*my error\w*"));

            Task <string> task = lloidc.GetAccessTokenFromCodeAsync("", "");

            yield return(AsyncTest.WaitForTask(task));

            string res = task.Result;

            Assert.IsEmpty(res);
        }
Ejemplo n.º 27
0
        public IEnumerator CheckAccessTokenAsync_WebResponseSuccessful_ReturnsTrue()
        {
            LearningLayersOidcProvider lloidc        = new LearningLayersOidcProvider();
            IRestConnector             restConnector = A.Fake <IRestConnector>();

            A.CallTo(() => restConnector.GetAsync(A <string> .Ignored))
            .Returns(new WebResponse <string>("answer", null, 200));
            lloidc.RestConnector = restConnector;
            LearningLayersUserInfo userInfo   = new LearningLayersUserInfo("tester", "*****@*****.**", "Tester");
            IJsonSerializer        serializer = A.Fake <IJsonSerializer>();

            A.CallTo(() => serializer.FromJson <LearningLayersUserInfo>(A <string> .Ignored))
            .Returns(userInfo);
            lloidc.JsonSerializer = serializer;

            Task <bool> task = lloidc.CheckAccessTokenAsync("");

            yield return(AsyncTest.WaitForTask(task));

            bool res = task.Result;

            Assert.IsTrue(res);
        }