public async Task TestImage() { //Perpare TestingContext context = new TestingContext(); InitContext(context); context.DependencyMap[typeof(IBinaryService)] = context.GetService <BinaryService>(); IQuestionService questionService = InitQuestionService(context); //Add Q QuestionDto qdto = new QuestionDto() { Title = "Bla", Explanation = "bla", Language = "De", }; int newId = await questionService.InsertQuestionAsync(qdto); //Add Binary IBinaryService binaryService = context.GetSimple <IBinaryService>(); int id = await binaryService.AddBinaryAsync(new BinaryDto { ContentDisposition = "ContentDisposition", ContentType = "ContentType", FileName = "FileName", Name = "Name", Length = 2334, }); ImageDto imageDto = new ImageDto() { IdBinary = id, Full = false, Height = 124, Width = 64, }; imageDto = await questionService.AddImageAsync(imageDto); QuestionDto questionDto = await questionService.GetQuestionAsync(newId); questionDto.Images.Add(imageDto); await questionService.UpdateQuestionAsync(questionDto); questionDto = await questionService.GetQuestionAsync(newId); Assert.True(questionDto.Images.Count == 1); }
public async Task SaveBinaryTest() { TestingContext testingContext = new TestingContext(); testingContext.AddAdminPrincipalMock(); testingContext.AddLogServiceMock(); testingContext.AddRealDb(); testingContext.AddUserService(); IBinaryService service = testingContext.GetService <BinaryService>(); string testWord = "Hello World"; var bytes = System.Text.Encoding.UTF8.GetBytes(testWord); MemoryStream stream = new MemoryStream(); stream.Write(bytes, 0, bytes.Length); stream.Flush(); stream.Seek(0, SeekOrigin.Begin); BinaryDto binaryDto = new BinaryDto { ContentDisposition = "ContentDisposition", ContentType = "ContentType", FileName = "FileName", Name = "Name", Length = 2334, }; int id = await service.AddBinaryAsync(binaryDto); //Act await service.SaveAsync(id, stream); //Assert Stream streamToAssert = await service.GetBinaryAsync(id); StreamReader reader = new StreamReader(streamToAssert); string text = reader.ReadToEnd(); Assert.Equal(testWord, text); //Cleanup await service.DeleteBinaryAsync(id); }