Ejemplo n.º 1
0
        public void ShouldCreateRport()
        {
            const long   projectId = 213;
            const string name      = "report name";
            const string desc      = "report desc";
            const string rule      = "repo rule";
            const bool   isSystem  = true;

            const long userId = 12342;

            _reportRepository
            .Setup(_ => _.Get(projectId, name))
            .Returns(Enumerable.Empty <Reports>().AsQueryable());

            _reportAuthorityValidator
            .Setup(_ => _.CanCreate(userId, projectId))
            .Returns(true);

            _userPrincipal
            .Setup(_ => _.Info)
            .Returns(new UserInfo
            {
                Id = userId
            });

            _target.Add(projectId, name, desc, rule, isSystem);

            _reportRepository
            .Verify(_ => _.Insert(It.Is <Reports>(r =>
                                                  r.CreatedById == userId &&
                                                  r.DisplayName == name &&
                                                  r.Description == desc &&
                                                  r.ModifiedById == userId &&
                                                  r.ProjectId == projectId &&
                                                  r.Rule == rule
                                                  )),
                    Times.Once);

            _reportRepository
            .Verify(_ => _.Save(), Times.Once);
        }
        /// <summary>
        ///   Processes the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        public void Process([NotNull] UpdateReportCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            if (command.Report.Id == null)
            {
                _reportStorage.Add(command.Report.ProjectId,
                                   command.Report.Name,
                                   command.Report.Description,
                                   command.Report.Rule);
            }
            else
            {
                _reportStorage.Update(command.Report.Id.Value,
                                      command.Report.Name,
                                      command.Report.Description,
                                      command.Report.Rule);
            }
        }