コード例 #1
0
        public FeedFineModel MapToFeedModelWithPayment(Fine fine, User issuer, User receiver, Payment payment)
        {
            FeedFineModel fineModel = new FeedFineModel {
                Id = fine.Id,
                IssuerId = fine.IssuerId,
                Reason = fine.Reason,
                SeconderId = fine.SeconderId,
                Pending = fine.Pending,
                AwardedDate = fine.AwardedDate,
                IssuerDisplayName = issuer.DisplayName,
                ReceiverDisplayName = receiver.DisplayName,
                ReceiverId = receiver.Id,
                ModifiedDate = fine.ModifiedDate,
                UserImage = receiver.Image,
                Platform = fine.Platform.GetDescription()
            };

            if(payment != null)
            {
                fineModel.PaidDate = payment.PaidDate;
                fineModel.PayerId = payment.PayerId;
                fineModel.PaymentImage = payment.PaymentImage.ImageBytes.ToString();
            }

            return fineModel;
        }
コード例 #2
0
        public FeedFineModel MapToFeedModel(Fine fine, User issuer, User receiver, User seconder)
        {
            FeedFineModel model = this.MapToFeedModelWithPayment(fine, issuer, receiver, null);

            model.Seconder = seconder != null ? seconder.DisplayName : null;

            return model;
        }
コード例 #3
0
        private ValidationResult ValidateFine(Fine fine)
        {
            ValidationResult validationResult = new ValidationResult();

            if (fine.Reason.IsNullOrEmpty())
            {
                validationResult.AddMessage(Severity.Error, "A fine requires a reason");
            }

            if (!this.userApi.IsValidFineIssuer(fine.IssuerId))
            {
                validationResult.AddMessage(Severity.Error, string.Format("Only {0} fines per user per day can be awarded", int.Parse(ConfigurationManager.AppSettings["MaxFinesPerUserPerDay"])));
            }

            return validationResult;
        }
コード例 #4
0
        public void SecondOldestPendingFine_SecondsCorrectFine()
        {
            // Arrange:
            IRepository<User, UserDataModel, Guid> userRepository = MockRepository.GenerateMock<IRepository<User, UserDataModel, Guid>>();
            IRepository<Payment, PaymentDataModel, Guid> paymentRepository = MockRepository.GenerateMock<IRepository<Payment, PaymentDataModel, Guid>>();
            IFineMapper fineMapper = MockRepository.GenerateMock<IFineMapper>();
            IUserMapper userMapper = MockRepository.GenerateMock<IUserMapper>();
            IPaymentMapper paymentMapper = MockRepository.GenerateMock<IPaymentMapper>();
            IExcelExportService<FineExportModel> excelExportService =
                MockRepository.GenerateMock<IExcelExportService<FineExportModel>>();

            var fine = new Fine{AwardedDate = DateTime.Now};
            var user = new User{Fines = new List<Fine>{fine, new Fine{AwardedDate = DateTime.Now.AddMinutes(1)}}};

            userRepository.Stub(x => x.FindAll(null)).IgnoreArguments().Return(new List<User> { user });

            var userModel = new UserModel();
            userMapper.Stub(x => x.MapToModelShallow(user)).Return(userModel);

            FineApi fineApi = new FineApi(userRepository, paymentRepository, fineMapper, userMapper, paymentMapper, excelExportService, null, null, null, null, null);

            // Pre-Assert:
            fine.Pending.Should().Be.True();

            // Act:
            fineApi.SecondOldestPendingFine(Guid.NewGuid());

            // Assert:
            fine.Pending.Should().Be.False();

            userRepository.AssertWasCalled(x => x.Save(user));
            fineMapper.AssertWasCalled(x => x.MapToModelWithUser(fine, userModel));
        }
コード例 #5
0
        public Fine IssueFine(Guid issuerId, string reason, PlatformType platformType, Guid? seconderId = null)
        {
            var fine = new Fine
                       {
                           IssuerId = issuerId,
                           Reason = reason,
                           SeconderId = seconderId,
                           AwardedDate = DateTime.UtcNow,
                           ModifiedDate = DateTime.UtcNow,
                           Platform = platformType
                       };

            this.Fines.Add(fine);

            return fine;
        }
コード例 #6
0
 public FineModel MapToModel(Fine fine, Payment payment)
 {
     return new FineModel
            {
                IssuerId = fine.IssuerId,
                Reason = fine.Reason,
                PaymentImageBytes = payment != null ? this.MapPaymentImage(payment.PaymentImage) : null,
                SeconderId = fine.SeconderId,
                Pending = fine.Pending,
                AwardedDate = fine.AwardedDate
            };
 }
コード例 #7
0
 public FineModel MapToModel(Fine fine)
 {
     return this.MapToModel(fine, null);
 }
コード例 #8
0
 public FineWithUserModel MapToModelWithUser(Fine fine, UserModel shallowUserModel, Payment payment)
 {
     return new FineWithUserModel
     {
         IssuerId = fine.IssuerId,
         Reason = fine.Reason,
         PaymentImageBytes = payment != null ? this.MapPaymentImage(payment.PaymentImage) : null,
         SeconderId = fine.SeconderId,
         Pending = fine.Pending,
         AwardedDate = fine.AwardedDate,
         User = shallowUserModel
     };
 }
コード例 #9
0
 public FineWithUserModel MapToModelWithUser(Fine fine, UserModel shallowUserModel)
 {
     return this.MapToModelWithUser(fine, shallowUserModel, null);
 }