public void Can_send_email_send_event()
        {
            // Arrange
            _emailNotificationWorker.Start();
            var message = new EmailCommandMessage("*****@*****.**", "Fromy Fromerson", "*****@*****.**", "Toto Toterson", "subject", "message");

            _serviceBus.PublishMessage(message);

            var events = _eventRepository.Events.Where(x => x.DataType == typeof(NotificationSentEvent).Name);

            Assert.IsNotEmpty(events);
            Assert.AreEqual(1, events.Count());

            var notificationSendEvent = JsonConvert.DeserializeObject <NotificationSentEvent>(events.First().Data, new JsonSerializerSettings
            {
                NullValueHandling     = NullValueHandling.Ignore,
                ReferenceLoopHandling = ReferenceLoopHandling.Serialize
            });

            Assert.AreEqual(notificationSendEvent.Message, message.Body);
            Assert.AreEqual(notificationSendEvent.Status, NotificationStatus.Send);
            Assert.AreEqual(notificationSendEvent.Type, NotificationType.Email);
        }
        public void Can_process_licensee_updated()
        {
            // Arrange
            var licensee           = BrandTestHelper.CreateLicensee(false);
            var newName            = TestDataGenerator.GetRandomString(5);
            var newCompanyName     = newName + " Inc.";
            var newEmail           = TestDataGenerator.GetRandomEmail();
            var newAffiliateSystem = TestDataGenerator.GetRandomNumber(2) > 1;
            var newContractStart   = DateTimeOffset.UtcNow.Date.AddDays(-TestDataGenerator.GetRandomNumber(30));
            var newContractEnd     = newContractStart.AddMonths(3);

            // Act
            var @event = new LicenseeUpdated(new Licensee
            {
                Id              = licensee.Id,
                Name            = newName,
                CompanyName     = newCompanyName,
                Email           = newEmail,
                AffiliateSystem = newAffiliateSystem,
                ContractStart   = newContractStart,
                ContractEnd     = newContractEnd
            });

            _serviceBus.PublishMessage(@event);

            // Assert
            Assert.AreEqual(2, _reportRepository.LicenseeRecords.Count());
            var record = _reportRepository.LicenseeRecords.Last();

            Assert.AreEqual(licensee.Id, record.LicenseeId);
            Assert.AreEqual(newName, record.Name);
            Assert.AreEqual(newCompanyName, record.CompanyName);
            Assert.AreEqual(newEmail, record.EmailAddress);
            Assert.AreEqual(newAffiliateSystem, record.AffiliateSystem);
            Assert.AreEqual(newContractStart.Date, record.ContractStart.Date);
            Assert.AreEqual(newContractEnd.Date, record.ContractEnd.Value.Date);
            Assert.AreEqual(licensee.Status.ToString(), record.Status);
            record.Updated.Should().BeCloseTo(@event.EventCreated);
            Assert.AreEqual("SuperAdmin", record.UpdatedBy);
        }
 public void Consume(IDomainEvent message)
 {
     _fakeServiceBus.PublishMessage(message, saveToEventStore: false);
 }