Thanks Chrisk,
I know the underlying NotificationPublisher uses BackgroundJobs, as well as the NotificationDistributer but not sure how I can test my interface as it will not mock the underlying class.
Thanks for your help
Hi,
I am having an issue with testing if a notification is received. I have set up a unit test to but my test never completes, when I debug the test when it hits my publish method it just ends. I am passing a list of of users so it should not be anything to do with subscriptions.
My Test
public class Publisher_Tests : FooTestBase
{
private readonly IPublisher _notificationPublisher;
private readonly IUserNotificationManager _userNotificationManager;
public Publisher_Tests()
{
_notificationPublisher = Resolve<IPublisher>();
_userNotificationManager = Resolve<IUserNotificationManager>();
}
[Fact]
public void Publish_ShouldPublishGeneralNotification()
{
string notificationName = "TestGeneralNotification";
UserIdentifier userIndentifier = new UserIdentifier(1, 2);
List<UserIdentifier> userIdentifiers = new List<UserIdentifier>
{
userIndentifier
};
_notificationPublisher.Publish(notificationName, userIdentifiers);
UsingDbContext(context =>
{
var output = _userNotificationManager.GetUserNotificationCount(userIndentifier);
output.ShouldBeGreaterThan(0);
});
}
}
My Method
public class Publisher : DomainService, IPublisher
{
private readonly INotificationPublisher _notificationPublisher;
public Publisher(INotificationPublisher notificationPublisher)
{
_notificationPublisher = notificationPublisher;
}
public void Publish(string notificationName, List<UserIdentifier> userIdentifiers)
{
_notificationPublisher.Publish(notificationName, null, null, NotificationSeverity.Info, userIdentifiers.ToArray());
}
public async Task PublishAsync(string notificationName, List<UserIdentifier> userIdentifiers)
{
await _notificationPublisher.PublishAsync(notificationName, null, null, NotificationSeverity.Info, userIdentifiers.ToArray());
}
}
Any help would be really appreciated.
Hello!
First of all love your work!
I have just decided to create a new project with the latest templates (Amazing notifications/signalr stuff) and for the first time I decided to go TDD. I have not done much testing before and my async mental strength is lacking. However I spotted this and I am not sure it is a bug or I am not understanding the logic.
[Fact]
public async Task CreateUser_Test()
{
//Act
await _userAppService.CreateUser(
new CreateUserInput
{
EmailAddress = "[email protected]",
IsActive = true,
Name = "John",
Surname = "Nash",
Password = "123qwe",
UserName = "john.nash"
});
await UsingDbContextAsync(async context =>
{
var johnNashUser = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.naash");
johnNashUser.ShouldNotBeNull();
});
}
[Fact]
public async Task CreateUser_Without_Async_Context_Test()
{
//Act
await _userAppService.CreateUser(
new CreateUserInput
{
EmailAddress = "[email protected]",
IsActive = true,
Name = "John",
Surname = "Nash",
Password = "123qwe",
UserName = "john.nash"
});
await UsingDbContext(async context =>
{
var johnNashUser = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.naash");
johnNashUser.ShouldNotBeNull();
});
}
I have set it so they will both fail as the username should not match however the default test with UsingDbContextAsync will return a NULL but will not fail the test.
:? :?
If I correct the Username they will both pass.
Thanks
Thanks for getting back so quickly.
I guess you mean IUnitOfWorkManager (in case anyone copy and pastes)
I knew it had to be UnitOfWork but I completely missed the current section. Can not believe I missed it in the documents.
Thanks once again!
Next time I am in Istanbul the beers are on me (I married a Turkish woman so will be sooner rather than later)
Danny
First of all cok tesekkurler!
Boilerplate and Module Zero are amazing. I have been playing with them for over 6 months and they are brilliant, also documentation is spot on.
However, I am stuck on what is probably a straight forward problem.
In my code I am currently creating a new Role, which I need to be added to the database so I can get the Id to add permissions. Usually I would have done context.SaveChanges()
if (role.Id == 0)
{
IdentityResult result = await _roleManager.CheckDuplicateRoleNameAsync(null, role.Name, role.DisplayName);
if (!result.Succeeded)
{
throw new UserFriendlyException(result.Errors.FirstOrDefault().ToString());
}
else
{
IdentityResult createRole = await _roleManager.CreateAsync(role);
if (!createRole.Succeeded)
{
throw new UserFriendlyException("Something went wrong, please try again");
}
// SAVE TO DATABASE
// GET ID OF NEW ROLE
// DO SOMETHING
}
}
Any help would be really appreciated.