public async Task register_RESULT_OK() { // arrange - mocking IFormFile using a memory stream var obj = new FaceController(Services.GetRequiredService <IHostingEnvironment>(), Services.GetRequiredService <IFaceServiceClient>(), _storageService); string sampleFile = Path.Combine(Directory.GetCurrentDirectory(), "data", "joe_family.jpg"); ResponseModel uploadResult; using (var fs = new FileStream(sampleFile, FileMode.Open)) { FormFile f = new FormFile(fs, 0, fs.Length, "file", fs.Name); var uploadResultTemp = await obj.Upload(f); uploadResult = ((OkObjectResult)uploadResultTemp).Value as ResponseModel; } // act var registerResult = await obj.Register(uploadResult.Key, 1, "Helen"); // assert var storageObject = _storageService.Get(uploadResult.Key); Assert.Null(storageObject); // redetect & reidentify string sampleFileNext = Path.Combine(Directory.GetCurrentDirectory(), "data", "joe_family.jpg"); using (var fsNext = new FileStream(sampleFileNext, FileMode.Open)) { FormFile fNext = new FormFile(fsNext, 0, fsNext.Length, "file", fsNext.Name); var uploadResultTemp = await obj.Upload(fNext); Assert.Equal("Helen", (((OkObjectResult)uploadResultTemp).Value as ResponseModel).Faces[1].Candidates[0].PersonName); } }
public async Task upload_single_face_single_candidate_RESULT_OK() { // arrange - mocking IFormFile using a memory stream var fileMock = new Mock <IFormFile>(); string sampleFile = Path.Combine(Directory.GetCurrentDirectory(), "data", "joe_family.jpg"); using (var fs = new FileStream(sampleFile, FileMode.Open)) { fs.Position = 0; fileMock.Setup(m => m.OpenReadStream()).Returns(fs); fileMock.SetupAllProperties(); fileMock.SetupGet(p => p.FileName).Returns(sampleFile); // mocking Face Service Guid faceId = Guid.NewGuid(); Guid personId = Guid.NewGuid(); var faceServiceMock = new Mock <IFaceServiceClient>(); faceServiceMock.Setup(f => f.DetectAsync(It.IsAny <Stream>(), true, false, null)).Returns( Task.FromResult(new[] { new Face { FaceId = faceId } })); faceServiceMock.Setup(f => f.IdentifyAsync(It.IsAny <string>(), It.IsAny <Guid[]>(), 1)).Returns( Task.FromResult(new[] { new IdentifyResult { FaceId = faceId, Candidates = new [] { new Candidate { Confidence = 0.8, PersonId = personId } } } })); faceServiceMock.Setup(f => f.GetPersonAsync(It.IsAny <string>(), It.IsAny <Guid>())).Returns( Task.FromResult( new Person { PersonId = personId, Name = "Johannes" } )); var obj = new FaceController(Services.GetRequiredService <IHostingEnvironment>(), faceServiceMock.Object, _storageService); // act var result = await obj.Upload(fileMock.Object); // assert Assert.IsAssignableFrom <IActionResult>(result); Assert.IsType(typeof(OkObjectResult), result); Assert.IsType(typeof(ResponseModel), ((OkObjectResult)result).Value); Assert.True((((OkObjectResult)result).Value as ResponseModel).Faces.Count == 1); Assert.True((((OkObjectResult)result).Value as ResponseModel).Faces[0].Candidates.Count == 1); Assert.Equal("Johannes", (((OkObjectResult)result).Value as ResponseModel).Faces[0].Candidates[0].PersonName); } }
public async Task upload_single_face_single_candidate_RESULT_OK() { // arrange - mocking IFormFile using a memory stream string sampleFile = Path.Combine(Directory.GetCurrentDirectory(), "data", "joe_family.jpg"); using (var fs = new FileStream(sampleFile, FileMode.Open)) { FormFile f = new FormFile(fs, 0, fs.Length, "file", fs.Name); var obj = new FaceController(Services.GetRequiredService <IHostingEnvironment>(), Services.GetRequiredService <IFaceServiceClient>(), _storageService); // act var result = await obj.Upload(f); // assert Assert.IsAssignableFrom <IActionResult>(result); Assert.IsType(typeof(OkObjectResult), result); Assert.IsType(typeof(ResponseModel), ((OkObjectResult)result).Value); Assert.True((((OkObjectResult)result).Value as ResponseModel).Faces.Count == 4); } }