Example #1
0
        public void Arrange()
        {
            Setup();

            _emailTemplate = Builder <EMailTemplate> .CreateNew().Build();

            var templateName = EMailTemplateNames.PrintAssessorCoverLetters;

            MockHttp.When($"http://localhost:59022/api/v1/emailTemplates/{templateName}")
            .Respond("application/json", JsonConvert.SerializeObject(_emailTemplate));     // Respond with JSON

            _result = AssessorServiceApi.GetEmailTemplate(templateName).Result;
        }
 public void SendEmail(Person person, EMailTemplate template, string caseReference)
 {
     _mailingServiceGateway.Send(new Mail
     {
         Template = template,
         Payload  = JsonConvert.SerializeObject(new {
             Subject          = "Bridges or Structures Report - submission",
             Reference        = caseReference,
             FirstName        = person.FirstName,
             LastName         = person.LastName,
             RecipientAddress = person.Email
         })
     });
 }
Example #3
0
 public void SendEmail(Person person, EMailTemplate template, string caseReference)
 {
     _mailingServiceGateway.Send(new Mail
     {
         Template = template,
         Payload  = JsonConvert.SerializeObject(new {
             Subject          = "Parking dispensation request form - submission",
             Reference        = caseReference,
             FirstName        = person.FirstName,
             LastName         = person.LastName,
             RecipientAddress = person.Email
         })
     });
 }
        public void SendEmail(Person person, EMailTemplate template, string caseReference, StockportGovUK.NetStandard.Models.Addresses.Address street)
        {
            AbandonedVehicleMailModel submissionDetails = new AbandonedVehicleMailModel();

            _logger.LogInformation(caseReference, street, person);
            submissionDetails.Subject          = "Abandoned Vehicle Report - submission";
            submissionDetails.Reference        = caseReference;
            submissionDetails.StreetInput      = street.SelectedAddress;
            submissionDetails.FirstName        = person.FirstName;
            submissionDetails.LastName         = person.LastName;
            submissionDetails.RecipientAddress = person.Email;

            _mailingServiceGateway.Send(new Mail
            {
                Payload  = JsonConvert.SerializeObject(submissionDetails),
                Template = template
            });
        }
Example #5
0
        public void SendEmail(Person person, EMailTemplate template, string caseReference, Address street)
        {
            StreetReportMailModel submissionDetails = new StreetReportMailModel();

            _logger.LogInformation(caseReference, street, person);
            submissionDetails.Subject               = "Dropped kerb request - submission";
            submissionDetails.Reference             = caseReference;
            submissionDetails.FormType              = FormType.request;
            submissionDetails.ConcerningDescription = "a dropped kerb";
            submissionDetails.StreetInput           = street.SelectedAddress;
            submissionDetails.RecipientAddress      = person.Email;

            _mailingServiceGateway.Send(new Mail
            {
                Payload  = JsonConvert.SerializeObject(submissionDetails),
                Template = template
            });
        }
Example #6
0
        public static void AddTestData(AssessorDbContext context)
        {
            List <Organisation> organisations = new List <Organisation>();

            var existingOrganisation = context.Organisations.FirstOrDefault();

            if (existingOrganisation == null)
            {
                var firstOrganisation = new Organisation
                {
                    Id = Guid.NewGuid(),
                    EndPointAssessorName           = "BCS, The Chartered Institute for IT",
                    EndPointAssessorOrganisationId = "EPA000011",
                    EndPointAssessorUkprn          = 10022719,
                    Status             = OrganisationStatus.New,
                    OrganisationTypeId = 1
                };

                organisations.Add(firstOrganisation);

                context.Organisations.Add(firstOrganisation);
                context.SaveChanges();

                var secondOrganisation = new Organisation
                {
                    Id = Guid.NewGuid(),
                    EndPointAssessorName           = "BCS, The Chartered Institute for IT 1",
                    EndPointAssessorOrganisationId = "EPA000013",
                    EndPointAssessorUkprn          = 10033672,
                    Status             = OrganisationStatus.New,
                    OrganisationTypeId = 1
                };

                organisations.Add(secondOrganisation);
                context.Organisations.Add(secondOrganisation);
                context.SaveChanges();

                var thirdOrganisation = new Organisation
                {
                    Id = Guid.NewGuid(),
                    EndPointAssessorName           = "BCS, The Chartered Institute for IT 2",
                    EndPointAssessorOrganisationId = "EPA000014",
                    EndPointAssessorUkprn          = 1003367,
                    Status             = OrganisationStatus.New,
                    OrganisationTypeId = 1
                };

                context.Organisations.Add(thirdOrganisation);
                context.SaveChanges();

                organisations.Add(thirdOrganisation);

                var firstContact = new Contact
                {
                    Id          = Guid.NewGuid(),
                    Username    = "******",
                    Email       = "*****@*****.**",
                    DisplayName = "User One",
                    EndPointAssessorOrganisationId = firstOrganisation.EndPointAssessorOrganisationId,
                    Status         = ContactStatus.Live,
                    OrganisationId = firstOrganisation.Id,
                    Title          = "Mr",
                    FamilyName     = "One",
                    GivenNames     = "User",
                    SignInType     = "ASLogin",
                    SignInId       = Guid.Parse("089b2f10-5280-4a46-b23e-fa940c06d35d")
                };

                context.Contacts.Add(firstContact);

                var secondContact = new Contact
                {
                    Id          = Guid.NewGuid(),
                    Username    = "******",
                    Email       = "*****@*****.**",
                    DisplayName = "User Two",
                    EndPointAssessorOrganisationId = secondOrganisation.EndPointAssessorOrganisationId,
                    Status         = ContactStatus.Live,
                    OrganisationId = secondOrganisation.Id,
                    Title          = "Mrs",
                    FamilyName     = "Two",
                    GivenNames     = "User",
                    SignInType     = "ASLogin",
                    SignInId       = Guid.Parse("d4360834-d84b-4181-bd7a-a03cc581d02c")
                };

                context.Contacts.Add(secondContact);

                var thirdContact = new Contact
                {
                    Id          = Guid.NewGuid(),
                    Username    = "******",
                    Email       = "*****@*****.**",
                    DisplayName = "User Three",
                    EndPointAssessorOrganisationId = thirdOrganisation.EndPointAssessorOrganisationId,
                    Status         = ContactStatus.Live,
                    OrganisationId = thirdOrganisation.Id,
                    Title          = "Miss",
                    FamilyName     = "Three",
                    GivenNames     = "User",
                    SignInType     = "ASLogin",
                    SignInId       = Guid.Parse("f205e897-0e0b-40fb-9175-8a9a44cd4ff6")
                };

                context.Contacts.Add(thirdContact);
                context.SaveChanges();


                context.ContactRoles.AddRange(
                    new ContactRole()
                {
                    ContactId = firstContact.Id, Id = Guid.NewGuid(), RoleName = "SuperUser"
                },
                    new ContactRole()
                {
                    ContactId = secondContact.Id, Id = Guid.NewGuid(), RoleName = "SuperUser"
                },
                    new ContactRole()
                {
                    ContactId = thirdContact.Id, Id = Guid.NewGuid(), RoleName = "SuperUser"
                });


                // create 30 certificates which will not have any duplicate standard codes
                for (int i = 0; i <= 30; i++)
                {
                    var certificateReference = $"104123{i:00}";
                    var achievementDate      = DateTime.Now.AddDays(-1);
                    var grade      = CertificateGrade.Pass;
                    var epaOutcome = EpaOutcome.Pass;

                    var certificateData = new CertificateData
                    {
                        AchievementDate     = achievementDate,
                        ContactName         = "Contact One",
                        ContactOrganisation = "1234" + i,
                        Department          = "Human Resources",
                        ContactAddLine1     = "1 Alpha Drive",
                        ContactAddLine2     = "Oakhalls",
                        ContactAddLine3     = "Malvern",
                        ContactAddLine4     = "Worcs",
                        ContactPostCode     = "B60 2TY",
                        CourseOption        = "French",
                        LearnerFamilyName   = "Gouge",
                        LearnerGivenNames   = "David",
                        ProviderName        = "Test Provider",
                        OverallGrade        = grade,

                        Registration      = "Registered",
                        LearningStartDate = DateTime.Now.AddDays(10),

                        StandardReference       = i.ToString(),
                        StandardLevel           = 1,
                        StandardName            = "Test",
                        StandardPublicationDate = DateTime.Now,
                        FullName = "David Gouge",

                        EpaDetails = new EpaDetails
                        {
                            EpaReference     = certificateReference,
                            LatestEpaDate    = achievementDate,
                            LatestEpaOutcome = epaOutcome,
                            Epas             = new List <EpaRecord> {
                                new EpaRecord {
                                    EpaDate = achievementDate, EpaOutcome = epaOutcome
                                }
                            }
                        }
                    };

                    var certificate = new Certificate
                    {
                        Id                   = Guid.NewGuid(),
                        OrganisationId       = firstOrganisation.Id,
                        CertificateData      = JsonConvert.SerializeObject(certificateData),
                        Status               = CertificateStatus.Submitted,
                        CreatedBy            = "user2",
                        CertificateReference = certificateReference,
                        Uln                  = 1111111111,
                        ProviderUkPrn        = 12345678
                    };

                    switch (i)
                    {
                    case 0:
                        certificate.StandardCode = 93;
                        break;

                    case 1:
                        certificate.StandardCode = 90;
                        break;

                    case 2:
                        certificate.StandardCode = 33;
                        break;

                    case 3:
                        certificate.StandardCode = 44;
                        break;

                    case 4:
                        certificate.StandardCode = 45;
                        break;

                    case 5:
                        certificate.StandardCode = 46;
                        break;

                    case 6:
                        certificate.StandardCode = 47;
                        break;

                    case 7:
                        certificate.StandardCode = 48;
                        break;

                    case 8:
                        certificate.StandardCode = 49;
                        break;

                    case 9:
                        certificate.StandardCode = 50;
                        break;

                    case 10:
                        certificate.StandardCode = 51;
                        break;

                    case 11:
                        certificate.StandardCode = 52;
                        break;

                    case 12:
                        certificate.StandardCode = 53;
                        break;

                    default:
                        certificate.StandardCode = i;
                        break;
                    }

                    context.Certificates.Add(certificate);

                    var certificateLog = new CertificateLog
                    {
                        Id              = Guid.NewGuid(),
                        Action          = "Submitted",
                        CertificateId   = certificate.Id,
                        CertificateData = JsonConvert.SerializeObject(certificateData),
                        Certificate     = certificate,
                        EventTime       = DateTime.Now,
                        Status          = CertificateStatus.Submitted,
                        Username        = "******"
                    };

                    context.CertificateLogs.Add(certificateLog);

                    context.SaveChanges();

                    var ilr = new Ilr()
                    {
                        Uln            = certificate.Uln,
                        GivenNames     = "Karla",
                        FamilyName     = "Hawkins",
                        UkPrn          = firstOrganisation.EndPointAssessorUkprn.Value,
                        StdCode        = certificate.StandardCode,
                        LearnStartDate = new DateTime(2015, 8, 9),
                        EpaOrgId       = firstOrganisation.EndPointAssessorOrganisationId,
                        CreatedAt      = new DateTime(2018, 1, 1)
                    };

                    context.Ilrs.Add(ilr);
                    context.SaveChanges();
                }

                var emailTemplate = new EMailTemplate
                {
                    Id           = Guid.NewGuid(),
                    Recipients   = "*****@*****.**",
                    TemplateId   = "5b171b91-d406-402a-a651-081cce820acb",
                    TemplateName = "PrintAssessorCoverLetters",
                };

                context.EMailTemplates.Add(emailTemplate);
                context.SaveChanges();

                context.SaveChanges();
            }
        }
        public void Arrange()
        {
            EpaOrganisation = new EpaOrganisation
            {
                Id             = Guid.NewGuid(),
                OrganisationId = "EPA0001"
            };

            _eMailTemplate = new EMailTemplate
            {
                TemplateName = "EmailTemplate"
            };

            _eMailTemplateQueryRepository = new Mock <IEMailTemplateQueryRepository>();
            _eMailTemplateQueryRepository.Setup(c => c.GetEmailTemplate(It.IsAny <string>()))
            .ReturnsAsync(_eMailTemplate);

            _mediator = new Mock <IMediator>();

            _mediator.Setup(c => c.Send(
                                It.Is <GetAssessmentOrganisationRequest>(p => p.OrganisationId == EpaOrganisation.OrganisationId),
                                It.IsAny <CancellationToken>()))
            .ReturnsAsync(EpaOrganisation);

            _firstLiveContact = new ContactIncludePrivilegesResponse()
            {
                Contact = new ContactResponse
                {
                    Email       = "*****@*****.**",
                    DisplayName = "First Live Person",
                    Status      = ContactStatus.Live
                }
            };
            _firstLiveContact.Privileges.Add(new PrivilegeResponse
            {
                Key = ChangeOrganisationDetailsContactsPrivilege.Privilege.Key
            });

            _secondLiveContact = new ContactIncludePrivilegesResponse()
            {
                Contact = new ContactResponse
                {
                    Email       = "*****@*****.**",
                    DisplayName = "Second Live Person",
                    GivenNames  = "Second Live",
                    Status      = ContactStatus.Live
                }
            };
            _secondLiveContact.Privileges.Add(new PrivilegeResponse
            {
                Key = ChangeOrganisationDetailsContactsPrivilege.Privilege.Key
            });
            _secondLiveContact.Privileges.Add(new PrivilegeResponse
            {
                Key = ManageUsersContactsPrivilege.Privilege.Key
            });

            _thirdLiveContact = new ContactIncludePrivilegesResponse()
            {
                Contact = new ContactResponse
                {
                    Email       = "thirdliveorganisation.com",
                    DisplayName = "Third Live Person",
                    GivenNames  = "Third Live",
                    Status      = ContactStatus.Live
                }
            };
            _thirdLiveContact.Privileges.Add(new PrivilegeResponse
            {
                Key = ManageUsersContactsPrivilege.Privilege.Key
            });

            _firstPendingContact = new ContactIncludePrivilegesResponse()
            {
                Contact = new ContactResponse
                {
                    Email       = "*****@*****.**",
                    DisplayName = "First Pending Person",
                    GivenNames  = "First Pending",
                    Status      = ContactStatus.InvitePending
                }
            };
            _firstPendingContact.Privileges.Add(new PrivilegeResponse
            {
                Key = ManageUsersContactsPrivilege.Privilege.Key
            });

            _mediator.Setup(c => c.Send(
                                It.IsAny <GetAllContactsIncludePrivilegesRequest>(),
                                It.IsAny <CancellationToken>())
                            )
            .ReturnsAsync(new List <ContactIncludePrivilegesResponse>
            {
                _firstLiveContact,
                _secondLiveContact,
                _thirdLiveContact,
                _firstPendingContact
            });

            EditorCommon = _thirdLiveContact.Contact.DisplayName;

            _logger = new Mock <ILogger <SendOrganisationDetailsAmendedEmailHandler> >();

            // this callback is being used to capture the send email requests which are later
            // compared; this is done like this due to the anonymous object for Tokens
            // which cannot be verified in the normal style - NOTE: also the
            // Returns(Task.CompletedTask) which is necessary for a null returning async
            // Mock which is handled by a callback to avoid a NullReferenceException
            // during testing
            _emailRequestsSent = new List <string>();
            _mediator
            .Setup(c =>
                   c.Send(
                       It.IsAny <SendEmailRequest>(),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(new Unit())
            .Callback <IRequest, CancellationToken>((request, token) =>
            {
                var sendEmailRequest = request as SendEmailRequest;
                _emailRequestsSent.Add(JsonConvert.SerializeObject(new
                {
                    sendEmailRequest.Email,
                    EmailTemplate = sendEmailRequest.EmailTemplate.TemplateName,
                    sendEmailRequest.Tokens
                }));
            });

            _sut = new SendOrganisationDetailsAmendedEmailHandler(
                _eMailTemplateQueryRepository.Object, _mediator.Object, _logger.Object);
        }
Example #8
0
 public SendEmailRequest(string email, EMailTemplate emailTemplate, dynamic tokens)
 {
     EmailTemplate = emailTemplate;
     Email         = email;
     Tokens        = tokens;
 }
        public void SendEmail_ShouldCallMailingServiceGateway_WithCorrectEmailTemplate_ForJourney(EMailTemplate emailTemplate, string journey, string whatToReport = "flood")
        {
            var callbackValue = new Mail();

            // Arrange
            _mockMailingServiceGateway.Setup(_ => _.Send(It.IsAny <Mail>()))
            .Callback <Mail>(a => callbackValue = a);

            var floodingRequest = new FloodingRequest
            {
                WhereIsTheFlood       = journey,
                WhatDoYouWantToReport = whatToReport,
                Reporter = new ContactDetails
                {
                    EmailAddress = "EmailAddress"
                }
            };

            // Act
            _mailHelper.SendEmail(floodingRequest, "123456");

            // Assert
            _mockMailingServiceGateway.Verify(_ => _.Send(It.IsAny <Mail>()), Times.Once);
            Assert.Equal(emailTemplate, callbackValue.Template);
        }