Example #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var readCommand = new EntityIdentifierQuery <Guid, TenantUpdateModel>(User, Id);
            var updateModel = await Mediator.Send(readCommand);

            if (updateModel == null)
            {
                return(NotFound());
            }

            // only update input fields
            await TryUpdateModelAsync(
                updateModel,
                nameof(Entity),
                p => p.Name,
                p => p.Description,
                p => p.Slug,
                p => p.City,
                p => p.StateProvince,
                p => p.TimeZone,
                p => p.DomainName
                );

            var updateCommand = new EntityUpdateCommand <Guid, TenantUpdateModel, TenantReadModel>(User, Id, updateModel);
            var result        = await Mediator.Send(updateCommand);

            ShowAlert("Successfully saved tenant");

            return(RedirectToPage("/Global/Tenant/Edit", new { id = result.Id }));
        }
Example #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var readCommand = new EntityIdentifierQuery <Guid, LocationUpdateModel>(User, Id);
            var updateModel = await Mediator.Send(readCommand);

            if (updateModel == null)
            {
                return(NotFound());
            }

            // only update input fields
            await TryUpdateModelAsync(
                updateModel,
                nameof(Entity),
                p => p.Name,
                p => p.Description,
                p => p.AddressLine1,
                p => p.City,
                p => p.StateProvince,
                p => p.PostalCode
                );

            var updateCommand = new EntityUpdateCommand <Guid, LocationUpdateModel, LocationReadModel>(User, Id, updateModel);
            var result        = await Mediator.Send(updateCommand);

            ShowAlert("Successfully saved location");

            return(RedirectToPage("/Location/Edit", new { id = result.Id, tenant = TenantRoute }));
        }
Example #3
0
        private async Task <TopicReadModel> LoadTopic()
        {
            var command = new EntityIdentifierQuery <Guid, TopicReadModel>(User, Id);
            var result  = await Mediator.Send(command);

            return(result);
        }
Example #4
0
        protected override async Task <TReadModel> Process(EntityIdentifierQuery <TKey, TReadModel> request, CancellationToken cancellationToken)
        {
            var model = await Read(request.Id, cancellationToken)
                        .ConfigureAwait(false);

            return(model);
        }
        private async Task LoadSession()
        {
            var command = new EntityIdentifierQuery <Guid, SessionReadModel>(User, SessionId);
            var result  = await Mediator.Send(command);

            Session = result;
        }
Example #6
0
        protected virtual async Task <TReadModel> GetQuery(TKey id, CancellationToken cancellationToken = default(CancellationToken))
        {
            var command = new EntityIdentifierQuery <TKey, TEntity, TReadModel>(id, User);
            var result  = await Mediator.Send(command, cancellationToken).ConfigureAwait(false);

            return(result);
        }
Example #7
0
        protected virtual async Task <TReadModel> GetQuery(TKey id, CancellationToken cancellationToken = default)
        {
            var command = new EntityIdentifierQuery <TKey, TReadModel>(User, id);
            var result  = await Mediator.Send(command, cancellationToken);

            return(result);
        }
Example #8
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var readCommand = new EntityIdentifierQuery <Guid, InstructorUpdateModel>(User, Id);
            var updateModel = await Mediator.Send(readCommand);

            if (updateModel == null)
            {
                return(NotFound());
            }

            // only update input fields
            await TryUpdateModelAsync(
                updateModel,
                nameof(Entity),
                p => p.GivenName,
                p => p.FamilyName,
                p => p.DisplayName,
                p => p.JobTitle,
                p => p.EmailAddress,
                p => p.MobilePhone,
                p => p.BusinessPhone
                );

            var updateCommand = new EntityUpdateCommand <Guid, InstructorUpdateModel, InstructorReadModel>(User, Id, updateModel);
            var result        = await Mediator.Send(updateCommand);

            ShowAlert("Successfully saved instructor");

            return(RedirectToPage("/Instructor/View", new { id = result.Id, tenant = TenantRoute }));
        }
Example #9
0
        protected override async Task <CompleteModel> Process(SignUpCommand request, CancellationToken cancellationToken)
        {
            var principal = request.Principal;

            var updateCommand = new EntityUpsertCommand <Guid, SignUpUpdateModel, SignUpReadModel>(principal, request.Id, request.InstructorSignUp);
            var updateModel   = await _mediator.Send(updateCommand, cancellationToken);

            foreach (var signupTopic in request.InstructorSignUpTopics)
            {
                var signupTopicCommand = new EntityUpsertCommand <Guid, SignUpTopicUpdateModel, SignUpTopicReadModel>(principal, signupTopic.Id, signupTopic);
                var signupTopicModel   = await _mediator.Send(signupTopicCommand, cancellationToken);

                var topicId = signupTopicModel.TopicId;

                var topicReadCommand = new EntityIdentifierQuery <Guid, TopicUpdateModel>(principal, topicId);
                var topicModel       = await _mediator.Send(topicReadCommand, cancellationToken);

                topicModel.InstructorSlots = signupTopic.TopicInstructorSlots;

                var topicUpdateCommand = new EntityUpdateCommand <Guid, TopicUpdateModel, TopicReadModel>(principal, topicId, topicModel);
                var updatedModel       = await _mediator.Send(topicUpdateCommand, cancellationToken);
            }

            return(new CompleteModel());
        }
Example #10
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var readCommand = new EntityIdentifierQuery <Guid, DiscussionUpdateModel>(User, Id);
            var updateModel = await Mediator.Send(readCommand);

            if (updateModel == null)
            {
                return(NotFound());
            }

            // only update input fields
            await TryUpdateModelAsync(
                updateModel,
                nameof(Entity),
                p => p.Message
                );

            var updateCommand = new EntityUpdateCommand <Guid, DiscussionUpdateModel, DiscussionReadModel>(User, Id, updateModel);
            var result        = await Mediator.Send(updateCommand);

            ShowAlert("Successfully saved topic discussion message");

            return(RedirectToPage("/Topic/Discussion/View", new { Id = TopicId, tenant = TenantRoute }));
        }
Example #11
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var readCommand = new EntityIdentifierQuery <Guid, TopicUpdateModel>(User, Id);
            var updateModel = await Mediator.Send(readCommand);

            if (updateModel == null)
            {
                return(NotFound());
            }

            // only update input fields
            await TryUpdateModelAsync(
                updateModel,
                nameof(Entity),
                p => p.Title,
                p => p.Description,
                p => p.CalendarYear,
                p => p.TargetMonth,
                p => p.LeadInstructorId,
                p => p.IsRequired
                );

            var updateCommand = new EntityUpdateCommand <Guid, TopicUpdateModel, TopicReadModel>(User, Id, updateModel);
            var result        = await Mediator.Send(updateCommand);

            ShowAlert("Successfully saved topic");

            return(RedirectToPage("/Topic/View", new { id = result.Id, tenant = TenantRoute }));
        }
Example #12
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                Topics = await LoadTopics();

                return(Page());
            }

            var readCommand = new EntityIdentifierQuery <Guid, SignUpUpdateModel>(User, Id);
            var updateModel = await Mediator.Send(readCommand);

            if (updateModel == null)
            {
                return(NotFound());
            }

            // only update input fields
            await TryUpdateModelAsync(
                updateModel,
                nameof(Entity),
                p => p.Name,
                p => p.Description
                );

            var updateCommand = new SignUpCommand(User, Id, updateModel, SignUpTopics);
            var result        = await Mediator.Send(updateCommand);

            ShowAlert("Successfully saved instructor signup");

            return(RedirectToPage("/signup/View", new { id = Id, tenant = TenantRoute }));
        }
Example #13
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var readCommand = new EntityIdentifierQuery <Guid, MemberUpdateModel>(User, Id);
            var updateModel = await Mediator.Send(readCommand);

            if (updateModel == null)
            {
                return(NotFound());
            }

            // only update input fields
            await TryUpdateModelAsync(
                updateModel,
                nameof(Entity),
                p => p.DisplayName,
                p => p.SortName,
                p => p.FamilyName,
                p => p.GivenName,
                p => p.JobTitle,
                p => p.Email,
                p => p.PhoneNumber
                );

            // compute sort name
            if (updateModel.SortName.IsNullOrWhiteSpace())
            {
                updateModel.SortName = ToSortName(updateModel);
            }

            if (IsMemberDisabled && updateModel.LockoutEnd == null)
            {
                updateModel.LockoutEnd = DateTimeOffset.Now.AddYears(100);
            }
            else if (!IsMemberDisabled && updateModel.LockoutEnd.HasValue)
            {
                updateModel.LockoutEnd = null;
            }

            var updateCommand = new EntityUpdateCommand <Guid, MemberUpdateModel, MemberReadModel>(User, Id, updateModel);
            var updateResult  = await Mediator.Send(updateCommand);

            // make sure correct user and tenant
            Membership.UserId   = updateResult.Id;
            Membership.TenantId = Tenant.Value.Id;

            var membershipCommand = new TenantMembershipCommand(User, Membership);
            var membershipResult  = await Mediator.Send(membershipCommand);

            ShowAlert("Successfully saved member");

            return(RedirectToPage("/Member/Edit", new { id = Id, tenant = TenantRoute }));
        }
Example #14
0
        private async Task <TemplateReadModel> LoadTemplate()
        {
            if (TemplateId == null)
            {
                return(await Task.FromResult <TemplateReadModel>(null));
            }

            var command = new EntityIdentifierQuery <Guid, TemplateReadModel>(User, TemplateId.Value);
            var result  = await Mediator.Send(command);

            return(result);
        }
Example #15
0
        public void ConstructorWithParameters()
        {
            var id = Guid.NewGuid();
            var identifierQuery = new EntityIdentifierQuery <Guid, LocationReadModel>(MockPrincipal.Default, id);

            identifierQuery.Should().NotBeNull();

            identifierQuery.Id.Should().NotBe(Guid.Empty);
            identifierQuery.Id.Should().Be(id);

            identifierQuery.Principal.Should().NotBeNull();
        }
Example #16
0
        protected override async Task <PaymentReadModel> ProcessAsync(PaymentApprovalCommand <Guid, PaymentTransaction, PaymentReadModel> message, CancellationToken cancellationToken)
        {
            var command = new EntityIdentifierQuery <Guid, PaymentTransaction, PaymentReadModel>(message.Id, message.Principal);
            var result  = await Mediator.Send(command, cancellationToken).ConfigureAwait(false);

            if (result == null)
            {
                throw new DomainException(422, $"Payment Id '{message.Id}' not found.");
            }

            if (result.Status != message.PaymentStatus)
            {
                var commandCourse = new EntityIdentifierQuery <Guid, TrainingCourse, CourseReadModel>(result.CourseId.Value, message.Principal);
                var resultCourse  = await Mediator.Send(commandCourse, cancellationToken).ConfigureAwait(false);

                if (resultCourse == null)
                {
                    throw new DomainException(422, $"Course Id '{result.CourseId}' not found.");
                }

                if (resultCourse.MaxAttendee == resultCourse.NoAttendee)
                {
                    throw new DomainException(422, $"Course '{resultCourse.Title}' is already full.");
                }
                var mapCourse = _mapper.Map <CourseUpdateModel>(resultCourse);
                mapCourse.MaxAttendee = mapCourse.MaxAttendee - 1;
                mapCourse.NoAttendee  = mapCourse.NoAttendee + 1;

                var updateCourse = new EntityUpdateCommand <Guid, TrainingCourse, CourseUpdateModel, CourseReadModel>(resultCourse.Id, mapCourse, message.Principal);

                var mediatorCourse = await Mediator.Send(updateCourse, cancellationToken)
                                     .ConfigureAwait(false);

                result.Status = message.PaymentStatus;
                var map    = _mapper.Map <PaymentUpdateModel>(result);
                var update = new EntityUpdateCommand <Guid, PaymentTransaction, PaymentUpdateModel, PaymentReadModel>(message.Id, map, message.Principal);

                result = await Mediator.Send(update, cancellationToken).ConfigureAwait(false);

                var history      = _mapper.Map <PaymentTransactionHistory>(result);
                var dbSetHistory = _dataContext.Set <Data.Entities.PaymentTransactionHistory>();
                await dbSetHistory.AddAsync(history, cancellationToken).ConfigureAwait(false);

                await _dataContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

                var mapAttendee = _mapper.Map <TrainingBuildCoursesAttendeeCreatedModel>(result);

                var courseAttendee = new EntityCreateCommand <Core.Data.Entities.TrainingBuildCourseAttendee, TrainingBuildCoursesAttendeeCreatedModel, TrainingBuildCoursesAttendeeReadModel>(mapAttendee, message.Principal);

                var resultCourseAttendee = await Mediator.Send(courseAttendee, cancellationToken).ConfigureAwait(false);
            }
            return(result);
        }
        public virtual async Task <IActionResult> OnGetAsync()
        {
            var command = new EntityIdentifierQuery <Guid, TModel>(User, Id);

            var result = await Mediator.Send(command);

            if (result == null)
            {
                return(NotFound());
            }

            Entity = result;

            return(Page());
        }
        public async Task EntityIdentifierQuery()
        {
            var mediator = ServiceProvider.GetService <IMediator>();

            mediator.Should().NotBeNull();

            var mapper = ServiceProvider.GetService <IMapper>();

            mapper.Should().NotBeNull();

            var identifierQuery  = new EntityIdentifierQuery <string, PriorityReadModel>(MockPrincipal.Default, PriorityConstants.Normal.ToCosmosKey());
            var identifierResult = await mediator.Send(identifierQuery).ConfigureAwait(false);

            identifierResult.Should().NotBeNull();
            identifierResult.Id.Should().Be(PriorityConstants.Normal.Id);
        }
    protected override async Task <TReadModel> Process(EntityIdentifierQuery <TKey, TReadModel> request, CancellationToken cancellationToken)
    {
        if (request is null)
        {
            throw new ArgumentNullException(nameof(request));
        }

        var entity = await Repository
                     .FindAsync(request.Id, cancellationToken)
                     .ConfigureAwait(false);

        // convert entity to read model
        var model = Mapper.Map <TReadModel>(entity);

        return(model);
    }
        public async Task Upsert()
        {
            var key = ObjectId.GenerateNewId().ToString();

            var mediator = ServiceProvider.GetService <IMediator>();

            mediator.Should().NotBeNull();

            var mapper = ServiceProvider.GetService <IMapper>();

            mapper.Should().NotBeNull();

            // Update Entity
            var updateModel = Generator.Default.Single <TaskUpdateModel>();

            updateModel.Title       = "Upsert Test";
            updateModel.Description = "Insert " + DateTime.Now.Ticks;
            updateModel.StatusId    = StatusConstants.NotStarted.Id;
            updateModel.TenantId    = TenantConstants.Test.Id;

            var upsertCommandNew = new EntityUpsertCommand <string, TaskUpdateModel, TaskReadModel>(MockPrincipal.Default, key, updateModel);
            var upsertResultNew  = await mediator.Send(upsertCommandNew).ConfigureAwait(false);

            upsertResultNew.Should().NotBeNull();
            upsertResultNew.Id.Should().Be(key);

            // Get Entity by Key
            var identifierQuery  = new EntityIdentifierQuery <string, TaskReadModel>(MockPrincipal.Default, key);
            var identifierResult = await mediator.Send(identifierQuery).ConfigureAwait(false);

            identifierResult.Should().NotBeNull();
            identifierResult.Title.Should().Be(updateModel.Title);

            // update model
            updateModel.Description = "Update " + DateTime.Now.Ticks;

            // Upsert again, should be update
            var upsertCommandUpdate = new EntityUpsertCommand <string, TaskUpdateModel, TaskReadModel>(MockPrincipal.Default, key, updateModel);
            var upsertResultUpdate  = await mediator.Send(upsertCommandUpdate).ConfigureAwait(false);

            upsertResultUpdate.Should().NotBeNull();
            upsertResultUpdate.Description.Should().NotBe(upsertResultNew.Description);
        }
Example #21
0
    protected override async Task <TReadModel> Process(EntityIdentifierQuery <string, TReadModel> request, CancellationToken cancellationToken)
    {
        if (request is null)
        {
            throw new ArgumentNullException(nameof(request));
        }
        if (!CosmosKey.TryDecode(request.Id, out var id, out var partitionKey))
        {
            throw new InvalidOperationException("Invalid Cosmos Key format");
        }

        var entity = await Repository
                     .FindAsync(id, partitionKey, cancellationToken)
                     .ConfigureAwait(false);

        // convert deleted entity to read model
        var model = Mapper.Map <TReadModel>(entity);

        return(model);
    }
        public async Task Upsert()
        {
            var id  = ObjectId.GenerateNewId().ToString();
            var key = CosmosKey.Encode(id, id);

            var mediator = ServiceProvider.GetService <IMediator>();

            mediator.Should().NotBeNull();

            var mapper = ServiceProvider.GetService <IMapper>();

            mapper.Should().NotBeNull();

            // Update Entity
            var updateModel = Generator.Default.Single <AuditUpdateModel>();

            updateModel.Username = "******";
            updateModel.Content  = "Insert " + DateTime.Now.Ticks;

            var upsertCommandNew = new EntityUpsertCommand <string, AuditUpdateModel, AuditReadModel>(MockPrincipal.Default, key, updateModel);
            var upsertResultNew  = await mediator.Send(upsertCommandNew).ConfigureAwait(false);

            upsertResultNew.Should().NotBeNull();

            // Get Entity by Key
            var identifierQuery  = new EntityIdentifierQuery <string, AuditReadModel>(MockPrincipal.Default, key);
            var identifierResult = await mediator.Send(identifierQuery).ConfigureAwait(false);

            identifierResult.Should().NotBeNull();
            identifierResult.Username.Should().Be(updateModel.Username);

            // update model
            updateModel.Content = "Update " + DateTime.Now.Ticks;

            // Upsert again, should be update
            var upsertCommandUpdate = new EntityUpsertCommand <string, AuditUpdateModel, AuditReadModel>(MockPrincipal.Default, key, updateModel);
            var upsertResultUpdate  = await mediator.Send(upsertCommandUpdate).ConfigureAwait(false);

            upsertResultUpdate.Should().NotBeNull();
            upsertResultUpdate.Content.Should().NotBe(upsertResultNew.Content);
        }
Example #23
0
        public async Task <IActionResult> GetById(int id, CancellationToken cancellationToken)
        {
            var returnResponse = new EntityResponseModel <ProductReadDto>();

            try
            {
                var query  = new EntityIdentifierQuery <int, EntityResponseModel <ProductReadDto> >(id);
                var result = await Mediator.Send(query, cancellationToken).ConfigureAwait(false);

                if (result.ReturnStatus == false)
                {
                    return(BadRequest(result));
                }
                return(Ok(result));
            }
            catch (Exception ex)
            {
                returnResponse.ReturnStatus = false;
                returnResponse.ReturnMessage.Add(ex.Message);
                return(BadRequest(returnResponse));
            }
        }
Example #24
0
        protected override async Task <TReadModel> ProcessAsync(EntityIdentifierQuery <TKey, TEntity, TReadModel> message, CancellationToken cancellationToken)
        {
            var dbSet = _context
                        .Set <TEntity>();

            var keyValue = new object[] { message.Id };

            // find entity by message id
            var entity = await dbSet
                         .FindAsync(keyValue, cancellationToken)
                         .ConfigureAwait(false);

            if (entity == null)
            {
                return(default(TReadModel));
            }

            // return read model
            var model = _mapper.Map <TReadModel>(entity);

            return(model);
        }
Example #25
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var readCommand = new EntityIdentifierQuery <Guid, SessionUpdateModel>(User, Id);
            var updateModel = await Mediator.Send(readCommand);

            if (updateModel == null)
            {
                return(NotFound());
            }

            // only update input fields
            await TryUpdateModelAsync(
                updateModel,
                nameof(Entity),
                p => p.Note,
                p => p.StartDate,
                p => p.StartTime,
                p => p.EndDate,
                p => p.EndTime,
                p => p.LocationId,
                p => p.GroupId,
                p => p.LeadInstructorId
                );

            var updateCommand = new EntityUpdateCommand <Guid, SessionUpdateModel, SessionReadModel>(User, Id, updateModel);
            var result        = await Mediator.Send(updateCommand);

            var instructorCommand = new SessionInstructorUpdateCommand(User, Id, AdditionalInstructors);
            await Mediator.Send(instructorCommand);

            ShowAlert("Successfully saved topic session");

            return(RedirectToPage("/Topic/Session/View", new { result.Id, TopicId, tenant = TenantRoute }));
        }
Example #26
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var readCommand = new EntityIdentifierQuery <Guid, MemberUpdateModel>(User, Id);
            var updateModel = await Mediator.Send(readCommand);

            if (updateModel == null)
            {
                return(NotFound());
            }

            // only update input fields
            await TryUpdateModelAsync(
                updateModel,
                nameof(Entity),
                p => p.DisplayName,
                p => p.Email,
                p => p.PhoneNumber
                );

            var updateCommand = new EntityUpdateCommand <Guid, MemberUpdateModel, MemberReadModel>(User, Id, updateModel);
            var updateResult  = await Mediator.Send(updateCommand);

            // make sure correct user and tenant
            Membership.UserName = updateResult.UserName;
            Membership.TenantId = Tenant.Value.Id;

            var membershipCommand = new TenantMembershipCommand(User, Membership);
            var membershipResult  = await Mediator.Send(membershipCommand);

            ShowAlert("Successfully saved member");

            return(RedirectToPage("/Member/Edit", new { id = Id, tenant = TenantRoute }));
        }
Example #27
0
        public async Task FullTest()
        {
            var mediator = ServiceProvider.GetService <IMediator>();

            mediator.Should().NotBeNull();

            var mapper = ServiceProvider.GetService <IMapper>();

            mapper.Should().NotBeNull();

            // Create Entity
            var createModel = Generator.Default.Single <TenantCreateModel>();

            createModel.Slug     = "Test" + DateTime.Now.Ticks;
            createModel.TimeZone = "Central Standard Time";

            var createCommand = new EntityCreateCommand <TenantCreateModel, TenantReadModel>(MockPrincipal.Default, createModel);
            var createResult  = await mediator.Send(createCommand).ConfigureAwait(false);

            createResult.Should().NotBeNull();

            // Get Entity by Key
            var identifierQuery  = new EntityIdentifierQuery <Guid, TenantReadModel>(MockPrincipal.Default, createResult.Id);
            var identifierResult = await mediator.Send(identifierQuery).ConfigureAwait(false);

            identifierResult.Should().NotBeNull();
            identifierResult.Name.Should().Be(createModel.Name);

            // Query Entity
            var entityQuery = new EntityQuery
            {
                Sort = new[] { new EntitySort {
                                   Name = "Updated", Direction = "Descending"
                               } },
                Filter = new EntityFilter {
                    Name = "Slug", Value = "TEST"
                }
            };
            var listQuery = new EntityPagedQuery <TenantReadModel>(MockPrincipal.Default, entityQuery);

            var listResult = await mediator.Send(listQuery).ConfigureAwait(false);

            listResult.Should().NotBeNull();

            // Patch Entity
            var patchModel = new JsonPatchDocument <Tenant>();

            patchModel.Operations.Add(new Operation <Tenant>
            {
                op    = "replace",
                path  = "/Description",
                value = "Patch Update"
            });

            var patchCommand = new EntityPatchCommand <Guid, TenantReadModel>(MockPrincipal.Default, createResult.Id, patchModel);
            var patchResult  = await mediator.Send(patchCommand).ConfigureAwait(false);

            patchResult.Should().NotBeNull();
            patchResult.Description.Should().Be("Patch Update");

            // Update Entity
            var updateModel = mapper.Map <TenantUpdateModel>(patchResult);

            updateModel.Description = "Update Command";

            var updateCommand = new EntityUpdateCommand <Guid, TenantUpdateModel, TenantReadModel>(MockPrincipal.Default, createResult.Id, updateModel);
            var updateResult  = await mediator.Send(updateCommand).ConfigureAwait(false);

            updateResult.Should().NotBeNull();
            updateResult.Description.Should().Be("Update Command");

            // Delete Entity
            var deleteCommand = new EntityDeleteCommand <Guid, TenantReadModel>(MockPrincipal.Default, createResult.Id);
            var deleteResult  = await mediator.Send(deleteCommand).ConfigureAwait(false);

            deleteResult.Should().NotBeNull();
            deleteResult.Id.Should().Be(createResult.Id);
        }
        public async Task FullTest()
        {
            var mediator = ServiceProvider.GetService <IMediator>();

            mediator.Should().NotBeNull();

            var mapper = ServiceProvider.GetService <IMapper>();

            mapper.Should().NotBeNull();

            // Create Entity
            var createModel = Generator.Default.Single <TaskCreateModel>();

            createModel.Id          = ObjectId.GenerateNewId().ToString();
            createModel.Title       = "Testing";
            createModel.Description = "Test " + DateTime.Now.Ticks;
            createModel.StatusId    = StatusConstants.NotStarted.Id;
            createModel.TenantId    = TenantConstants.Test.Id;

            var createCommand = new EntityCreateCommand <TaskCreateModel, TaskReadModel>(MockPrincipal.Default, createModel);
            var createResult  = await mediator.Send(createCommand).ConfigureAwait(false);

            createResult.Should().NotBeNull();

            // Get Entity by Key
            var key              = createResult.Id;
            var identifierQuery  = new EntityIdentifierQuery <string, TaskReadModel>(MockPrincipal.Default, key);
            var identifierResult = await mediator.Send(identifierQuery).ConfigureAwait(false);

            identifierResult.Should().NotBeNull();
            identifierResult.Title.Should().Be(createModel.Title);

            // Query Entity
            var entityQuery = new EntityQuery
            {
                Sort = new List <EntitySort> {
                    new EntitySort {
                        Name = "Updated", Direction = "Descending"
                    }
                },
                Filter = new EntityFilter {
                    Name = "StatusId", Value = StatusConstants.NotStarted.Id
                }
            };
            var listQuery = new EntityPagedQuery <TaskReadModel>(MockPrincipal.Default, entityQuery);

            var listResult = await mediator.Send(listQuery).ConfigureAwait(false);

            listResult.Should().NotBeNull();

            // Patch Entity
            var patchModel = new JsonPatchDocument <Task>();

            patchModel.Operations.Add(new Operation <Task>
            {
                op    = "replace",
                path  = "/Title",
                value = "Patch Update"
            });

            var patchCommand = new EntityPatchCommand <string, TaskReadModel>(MockPrincipal.Default, key, patchModel);
            var patchResult  = await mediator.Send(patchCommand).ConfigureAwait(false);

            patchResult.Should().NotBeNull();
            patchResult.Title.Should().Be("Patch Update");

            // Update Entity
            var updateModel = mapper.Map <TaskUpdateModel>(patchResult);

            updateModel.Title = "Update Command";

            var updateCommand = new EntityUpdateCommand <string, TaskUpdateModel, TaskReadModel>(MockPrincipal.Default, key, updateModel);
            var updateResult  = await mediator.Send(updateCommand).ConfigureAwait(false);

            updateResult.Should().NotBeNull();
            updateResult.Title.Should().Be("Update Command");

            // Delete Entity
            var deleteCommand = new EntityDeleteCommand <string, TaskReadModel>(MockPrincipal.Default, key);
            var deleteResult  = await mediator.Send(deleteCommand).ConfigureAwait(false);

            deleteResult.Should().NotBeNull();
            deleteResult.Id.Should().Be(createResult.Id);
        }
Example #29
0
        public async Task FullTest()
        {
            var mediator = ServiceProvider.GetService <IMediator>();

            mediator.Should().NotBeNull();

            var mapper = ServiceProvider.GetService <IMapper>();

            mapper.Should().NotBeNull();

            // Create Entity
            var createModel = Generator.Default.Single <InstructorCreateModel>();

            createModel.TenantId    = Data.Constants.Tenant.Test;
            createModel.DisplayName = $"{createModel.GivenName} {createModel.FamilyName}";
            createModel.JobTitle    = "TEST";

            var createCommand = new EntityCreateCommand <InstructorCreateModel, InstructorReadModel>(MockPrincipal.Default, createModel);
            var createResult  = await mediator.Send(createCommand).ConfigureAwait(false);

            createResult.Should().NotBeNull();

            // Get Entity by Key
            var identifierQuery  = new EntityIdentifierQuery <Guid, InstructorReadModel>(MockPrincipal.Default, createResult.Id);
            var identifierResult = await mediator.Send(identifierQuery).ConfigureAwait(false);

            identifierResult.Should().NotBeNull();
            identifierResult.DisplayName.Should().Be(createModel.DisplayName);

            // Query Entity
            var entityQuery = new EntityQuery
            {
                Sort = new[] { new EntitySort {
                                   Name = "Updated", Direction = "Descending"
                               } },
                Filter = new EntityFilter {
                    Name = "JobTitle", Value = "TEST"
                }
            };
            var listQuery = new EntityPagedQuery <InstructorReadModel>(MockPrincipal.Default, entityQuery);

            var listResult = await mediator.Send(listQuery).ConfigureAwait(false);

            listResult.Should().NotBeNull();

            // Patch Entity
            var patchModel = new JsonPatchDocument <Instructor>();

            patchModel.Operations.Add(new Operation <Instructor>
            {
                op    = "replace",
                path  = "/DisplayName",
                value = "Patch Update"
            });

            var patchCommand = new EntityPatchCommand <Guid, InstructorReadModel>(MockPrincipal.Default, createResult.Id, patchModel);
            var patchResult  = await mediator.Send(patchCommand).ConfigureAwait(false);

            patchResult.Should().NotBeNull();
            patchResult.DisplayName.Should().Be("Patch Update");

            // Update Entity
            var updateModel = mapper.Map <InstructorUpdateModel>(patchResult);

            updateModel.DisplayName = "Update Command";

            var updateCommand = new EntityUpdateCommand <Guid, InstructorUpdateModel, InstructorReadModel>(MockPrincipal.Default, createResult.Id, updateModel);
            var updateResult  = await mediator.Send(updateCommand).ConfigureAwait(false);

            updateResult.Should().NotBeNull();
            updateResult.DisplayName.Should().Be("Update Command");

            // Delete Entity
            var deleteCommand = new EntityDeleteCommand <Guid, InstructorReadModel>(MockPrincipal.Default, createResult.Id);
            var deleteResult  = await mediator.Send(deleteCommand).ConfigureAwait(false);

            deleteResult.Should().NotBeNull();
            deleteResult.Id.Should().Be(createResult.Id);
        }
Example #30
0
        public void ConstructorNull()
        {
            var identifierQuery = new EntityIdentifierQuery <Guid, LocationReadModel>(null, Guid.Empty);

            identifierQuery.Should().NotBeNull();
        }