Пример #1
0
        public async Task Can_Change_Document_Status()
        {
            var dbContextOptions = CreateNewContextOptions();

            await CreateUserWithDocument(dbContextOptions);

            using (var context = new ApplicationDbContext(dbContextOptions))
            {
                var service = new DocumentsService(context);

                await service.ChangeStatus(1, DocumentStatus.Final);

                await context.SaveChangesAsync();
            }

            using (var context = new ApplicationDbContext(dbContextOptions))
            {
                var document = await context.Documents.Include(it => it.DocumentStates).FirstAsync();

                Assert.Equal(2, document.DocumentStates.Count);

                var states = await context.DocumentStates.ToListAsync();

                var oldState = states.First();
                var newState = states.Last();

                Assert.Equal(1, newState.Version);
                Assert.NotEqual(oldState.StatusDate, newState.StatusDate);
                Assert.Equal(DocumentStatus.Final, newState.DocumentStatus);
                Assert.Equal(oldState.IdDocumentData, newState.IdDocumentData);
            }
        }
Пример #2
0
        public async Task Can_Return_Documents_For_Task_From_Template()
        {
            var dbContextOptions = CreateNewContextOptions();
            var user             = await CreateUserWithDocument(dbContextOptions, 1);

            using (var context = new ApplicationDbContext(dbContextOptions))
            {
                context.Documents.AddRange(
                    new Document {
                    UserId = user.Id, DocumentStates = new List <DocumentState> {
                        new DocumentState()
                    }
                },
                    new Document {
                    UserId = user.Id, IdDocumentTask = 1, DocumentStates = new List <DocumentState> {
                        new DocumentState()
                    }
                });
                await context.SaveChangesAsync();
            };

            using (var context = new ApplicationDbContext(dbContextOptions))
            {
                var service = new DocumentsService(context);
                await service.ChangeStatus(2, DocumentStatus.Final);

                await service.ChangeStatus(3, DocumentStatus.Final);

                await context.SaveChangesAsync();
            }

            using (var context = new ApplicationDbContext(dbContextOptions))
            {
                var service = new DocumentsService(context);

                var good = await service.GetDocumentsForTask(user.Id, null);

                Assert.Equal(1, good.Count);
            }
        }
Пример #3
0
        public async Task Can_Return_Documents_For_Task()
        {
            var dbContextOptions = CreateNewContextOptions();
            var user1            = await CreateUserWithDocument(dbContextOptions, 1);

            var user2 = await CreateUserWithDocument(dbContextOptions, 2);

            using (var context = new ApplicationDbContext(dbContextOptions))
            {
                var service = new DocumentsService(context);
                await service.ChangeStatus(1, DocumentStatus.Final);

                await service.ChangeStatus(2, DocumentStatus.Final);

                await context.SaveChangesAsync();
            }

            using (var context = new ApplicationDbContext(dbContextOptions))
            {
                var service = new DocumentsService(context);

                var good = await service.GetDocumentsForTask(user1.Id, 1);

                Assert.Equal(1, good.Count);

                var good2 = await service.GetDocumentsForTask(user2.Id, 2);

                Assert.Equal(1, good2.Count);

                var bad = await service.GetDocumentsForTask(user1.Id, 2);

                Assert.Equal(0, bad.Count);

                var bad2 = await service.GetDocumentsForTask(user2.Id, 1);

                Assert.Equal(0, bad2.Count);
            }
        }