-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created test for interest status parameter and tag
- Loading branch information
Showing
13 changed files
with
849 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
Server/ReasnAPI/ReasnAPI.Tests/Services/ImageServiceTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using ReasnAPI.Models.Database; | ||
using ReasnAPI.Models.DTOs; | ||
using ReasnAPI.Services; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using Moq; | ||
using Moq.EntityFrameworkCore; | ||
|
||
|
||
namespace ReasnAPI.Tests.Services | ||
{ | ||
[TestClass] | ||
public class ImageServiceTests | ||
{ | ||
[TestMethod] | ||
public void CreateImage_ImageDoesNotExist_ImageCreated() | ||
{ | ||
var imageDto = new ImageDto | ||
{ | ||
ImageData = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }, | ||
}; | ||
|
||
var mockContext = new Mock<ReasnContext>(); | ||
mockContext.Setup(c => c.Images).ReturnsDbSet(new List<Image>()); | ||
|
||
var imageService = new ImageService(mockContext.Object); | ||
|
||
var result = imageService.CreateImage(imageDto); | ||
Assert.IsNotNull(result); | ||
} | ||
|
||
} | ||
} |
197 changes: 197 additions & 0 deletions
197
Server/ReasnAPI/ReasnAPI.Tests/Services/InterestServiceTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using ReasnAPI.Models.Database; | ||
using ReasnAPI.Models.DTOs; | ||
using ReasnAPI.Services; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using Moq; | ||
using Moq.EntityFrameworkCore; | ||
|
||
namespace ReasnAPI.Tests.Services | ||
{ | ||
[TestClass] | ||
public class InterestServiceTests | ||
{ | ||
[TestMethod] | ||
public void CreateInterest_InterestDoesNotExist_InterestCreated() | ||
{ | ||
var interestDto = new InterestDto | ||
{ | ||
Name = "TestInterest" | ||
}; | ||
|
||
var mockContext = new Mock<ReasnContext>(); | ||
mockContext.Setup(c => c.Interests).ReturnsDbSet(new List<Interest>()); | ||
|
||
var interestService = new InterestService(mockContext.Object); | ||
|
||
var result = interestService.CreateInterest(interestDto); | ||
|
||
Assert.AreEqual(interestDto.Name, result.Name); | ||
} | ||
|
||
[TestMethod] | ||
public void CreateInterest_InterestExists_InterestNotCreated() | ||
{ | ||
var interestDto = new InterestDto | ||
{ | ||
Name = "TestInterest" | ||
}; | ||
|
||
var mockContext = new Mock<ReasnContext>(); | ||
mockContext.Setup(c => c.Interests).ReturnsDbSet(new List<Interest> { new Interest { Name = "TestInterest" } }); | ||
|
||
var interestService = new InterestService(mockContext.Object); | ||
|
||
var result = interestService.CreateInterest(interestDto); | ||
|
||
Assert.IsNull(result); | ||
} | ||
|
||
[TestMethod] | ||
public void GetAllInterests_InterestExists_InterestsReturned() | ||
{ | ||
var mockContext = new Mock<ReasnContext>(); | ||
mockContext.Setup(c => c.Interests).ReturnsDbSet(new List<Interest> { new Interest { Name = "TestInterest" } }); | ||
|
||
var interestService = new InterestService(mockContext.Object); | ||
|
||
var result = interestService.GetAllInterests(); | ||
|
||
Assert.AreEqual(1, result.Count()); | ||
} | ||
|
||
[TestMethod] | ||
public void GetAllInterests_InterestDoesNotExists_NothingReturned() | ||
{ | ||
var mockContext = new Mock<ReasnContext>(); | ||
mockContext.Setup(c => c.Interests).ReturnsDbSet(new List<Interest>()); | ||
|
||
var interestService = new InterestService(mockContext.Object); | ||
|
||
var result = interestService.GetAllInterests(); | ||
|
||
Assert.AreEqual(0, result.Count()); | ||
} | ||
|
||
[TestMethod] | ||
public void GetInterestById_InterestDoesNotExist_NullReturned() | ||
{ | ||
var mockContext = new Mock<ReasnContext>(); | ||
mockContext.Setup(c => c.Interests).ReturnsDbSet(new List<Interest>()); | ||
|
||
var interestService = new InterestService(mockContext.Object); | ||
|
||
var result = interestService.GetInterestById(1); | ||
|
||
Assert.IsNull(result); | ||
} | ||
|
||
[TestMethod] | ||
public void GetInterestById_InterestExists_InterestReturned() | ||
{ | ||
var mockContext = new Mock<ReasnContext>(); | ||
mockContext.Setup(c => c.Interests).ReturnsDbSet(new List<Interest> { new Interest { Id = 1, Name = "TestInterest"} }); | ||
|
||
var interestService = new InterestService(mockContext.Object); | ||
|
||
var result = interestService.GetInterestById(1); | ||
|
||
Assert.AreEqual("TestInterest", result.Name); | ||
} | ||
|
||
[TestMethod] | ||
public void UpdateInterest_InterestExists_InterestUpdated() | ||
{ | ||
var interestDto = new InterestDto | ||
{ | ||
Name = "TestInterest1" | ||
}; | ||
|
||
var mockContext = new Mock<ReasnContext>(); | ||
mockContext.Setup(c => c.Interests).ReturnsDbSet(new List<Interest> { new Interest { Id = 1, Name = "TestInterest" } }); | ||
|
||
var interestService = new InterestService(mockContext.Object); | ||
|
||
var result = interestService.UpdateInterest(1, interestDto); | ||
|
||
Assert.AreEqual("TestInterest1", result.Name); | ||
} | ||
|
||
[TestMethod] | ||
public void UpdateInterest_InterestDoesNotExist_NullReturned() | ||
{ | ||
var interestDto = new InterestDto | ||
{ | ||
Name = "TestInterest" | ||
}; | ||
|
||
var mockContext = new Mock<ReasnContext>(); | ||
mockContext.Setup(c => c.Interests).ReturnsDbSet(new List<Interest>()); | ||
|
||
var interestService = new InterestService(mockContext.Object); | ||
|
||
var result = interestService.UpdateInterest(1, interestDto); | ||
|
||
Assert.IsNull(result); | ||
} | ||
|
||
[TestMethod] | ||
public void DeleteInterest_InterestExists_InterestDeleted() | ||
{ | ||
var mockContext = new Mock<ReasnContext>(); | ||
mockContext.Setup(c => c.Interests).ReturnsDbSet(new List<Interest> { new Interest { Id = 1, Name = "TestInterest" } }); | ||
|
||
var interestService = new InterestService(mockContext.Object); | ||
|
||
interestService.DeleteInterest(1); | ||
|
||
mockContext.Verify(c => c.SaveChanges(), Times.Once); | ||
} | ||
|
||
[TestMethod] | ||
public void DeleteInterest_InterestDoesNotExist_NothingDeleted() | ||
{ | ||
var mockContext = new Mock<ReasnContext>(); | ||
mockContext.Setup(c => c.Interests).ReturnsDbSet(new List<Interest>()); | ||
|
||
var interestService = new InterestService(mockContext.Object); | ||
|
||
interestService.DeleteInterest(1); | ||
|
||
mockContext.Verify(c => c.SaveChanges(), Times.Never); | ||
} | ||
|
||
[TestMethod] | ||
public void GetInterestsByFilter_InterestExists_InterestReturned() | ||
{ | ||
var mockContext = new Mock<ReasnContext>(); | ||
mockContext.Setup(c => c.Interests).ReturnsDbSet(new List<Interest> { new Interest { Name = "TestInterest" } }); | ||
|
||
var interestService = new InterestService(mockContext.Object); | ||
|
||
var result = interestService.GetInterestsByFilter(i => i.Name == "TestInterest").ToList(); | ||
|
||
Assert.AreEqual(1, result.Count()); | ||
|
||
} | ||
|
||
[TestMethod] | ||
public void GetInterestsByFilter_InterestDoesNotExist_NothingReturned() | ||
{ | ||
var mockContext = new Mock<ReasnContext>(); | ||
mockContext.Setup(c => c.Interests).ReturnsDbSet(new List<Interest>()); | ||
|
||
var interestService = new InterestService(mockContext.Object); | ||
|
||
var result = interestService.GetInterestsByFilter(i => i.Name == "TestInterest").ToList(); | ||
|
||
Assert.AreEqual(0, result.Count()); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.