Exemplo n.º 1
0
        public async Task TestTag()
        {
            //Prepare
            TestingContext testingContext = new TestingContext();

            testingContext.AddAdminPrincipalMock();
            testingContext.AddLogServiceMock();
            testingContext.AddRealDb();


            ApplicationDbContext context = testingContext.GetSimple <ApplicationDbContext>();

            Tag tag = new Tag
            {
                Name        = "Test",
                TagType     = TagType.Standard,
                Description = "Desc",
                ShortDescDe = "ShortDescDe",
                ShortDescEn = "ShortDescEn",
            };

            context.Tags.Add(tag);

            //Act
            await context.SaveChangesAsync();

            //Assert
            Assert.True(tag.Id > 0);

            //Cleanup
            context.Remove(tag);
            context.SaveChanges();
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public async Task TestQuestion()
        {
            //Prepare
            TestingContext testingContext = new TestingContext();

            testingContext.AddAdminPrincipalMock();
            testingContext.AddLogServiceMock();
            testingContext.AddRealDb();


            ApplicationDbContext context = testingContext.GetSimple <ApplicationDbContext>();


            Container container = new Container();

            context.Containers.Add(container);

            Question question1 = new Question();

            question1.Container = container;
            question1.Title     = "hello";
            question1.Text      = "Hello Text";
            question1.Status    = QuestionStatus.Created;
            question1.User      = await GetTestUserAsync(context);

            question1.Language     = Language.De;
            question1.QuestionType = QuestionType.SingleChoice;
            context.Questions.Add(question1);


            //Act
            context.SaveChanges();

            //Assert
            Question found = await context.FindAsync <Question>(question1.Id);

            Assert.NotNull(found);
            Assert.Equal(QuestionType.SingleChoice, found.QuestionType);

            //Cleanup
            context.Remove(question1);
            context.Remove(container);
            context.SaveChanges();
        }