Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

CustomerServiceTest.cs 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using Diligent.WebAPI.Business.Services;
  2. using Diligent.WebAPI.Data.Entities;
  3. using FluentAssertions;
  4. using Microsoft.AspNetCore.Identity;
  5. using Moq;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace Tests
  12. {
  13. [TestFixture]
  14. public class CustomerServiceTest
  15. {
  16. private CustomerService service;
  17. [Test]
  18. public async Task DeleteNotification_WhenUserIsNull_ReturnsFalse()
  19. {
  20. // Arrange
  21. var userManagerMock = new Mock<UserManager<Customer>>(Mock.Of<IUserStore<Customer>>(), null, null, null, null, null, null, null, null);
  22. userManagerMock.Setup(x => x.FindByIdAsync(It.IsAny<string>())).ReturnsAsync((Customer)null);
  23. service = new CustomerService(userManagerMock.Object);
  24. // Act
  25. var result = await service.DeleteNotification("", "");
  26. // Assert
  27. //Assert.IsFalse(result);
  28. result.Should().BeFalse();
  29. }
  30. [Test]
  31. public async Task DeleteNotification_UserIsNotNullAndNotificationIsNull_ReturnsFalse()
  32. {
  33. // Arrange
  34. var userManagerMock = new Mock<UserManager<Customer>>(Mock.Of<IUserStore<Customer>>(), null, null, null, null, null, null, null, null);
  35. var customer = new Customer
  36. {
  37. FirstName = "User",
  38. LastName = "Someone",
  39. Notifications = new List<Notification>
  40. {
  41. new Notification
  42. {
  43. RoomId = "Room1", Count = 1
  44. }
  45. }
  46. };
  47. userManagerMock.Setup(x => x.FindByIdAsync(It.IsAny<string>())).ReturnsAsync(customer);
  48. service = new CustomerService(userManagerMock.Object);
  49. // Act
  50. var result = await service.DeleteNotification("arg", "Room1");
  51. // Assert
  52. result.Should().BeTrue();
  53. }
  54. }
  55. }