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); }
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); }
public IEnumerator ExtendedLogging_Disabled_CommentsNotLogged() { mtlLibrary.ContentLoader = FakeContentLoaderFactory.CreateFakeLoader(content); mtlLibrary.ExtendedLogging = false; Task task = LoadLibrary(); yield return(AsyncTest.WaitForTask(task)); LogAssert.NoUnexpectedReceived(); }
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*")); }
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"); }
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); }
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); }
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); }
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); }
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); }
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); }
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"); }
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); }
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 }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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"); }
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); }
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); }
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); }
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); }
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); }