Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dot-net/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 4
Binary file added dot-net/UnitTesting/.vs/WriteUnitTest/v15/.suo
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,119 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace WriteUnitTest.UnitTests.Services
namespace WriteUnitTest.UnitTests.Services
{
using Entities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSubstitute;
using Repositories;
using WriteUnitTest.Services;

[TestClass]
public class LessonServiceUnitTests
{
private ILessonRepository lessonRepository;
private IModuleRepository moduleRepository;
private LessonService sut;

[TestInitialize]
public void Initialize()
{
lessonRepository = Substitute.For<ILessonRepository>();
moduleRepository = Substitute.For<IModuleRepository>();
sut = new LessonService(lessonRepository, moduleRepository);
}

[TestMethod]
public void UpdateLessonGrade_WhenGetLessonReturnsNull_ReturnNull()
{
const int lessonId = 12;
lessonRepository.GetLesson(lessonId).Returns((Lesson)null);

var result = sut.UpdateLesson(lessonId, 0d);

Assert.IsNull(result);
}

[TestMethod]
public void UpdateLessonGrade_WhenLessonIsPassed_ReturnUnmodifiedLesson()
{
const int lessonId = 12;
var lesson = new Lesson
{
LessonId = lessonId,
Grade = 80d,
IsPassed = true,
};
lessonRepository.GetLesson(lessonId).Returns(lesson);

var result = sut.UpdateLesson(lessonId, 0d);

Assert.AreEqual(lesson.LessonId, result.LessonId);
Assert.AreEqual(lesson.Grade, result.Grade);
Assert.AreEqual(lesson.IsPassed, result.IsPassed);
}

[TestMethod]
public void UpdateLessonGrade_WhenLessonFailedAndGetModuleReturnsNull_ReturnUpdatedLesson()
{
const double grade = 70d;
const int lessonId = 12;
var lesson = new Lesson
{
LessonId = lessonId,
Grade = 80d,
IsPassed = false,
};
lessonRepository.GetLesson(lessonId).Returns(lesson);
moduleRepository.GetModule(lessonId).Returns((Module)null);

var result = sut.UpdateLesson(lessonId, grade);

Assert.AreEqual(lesson.LessonId, result.LessonId);
Assert.AreEqual(grade, result.Grade);
Assert.AreEqual(lesson.IsPassed, result.IsPassed);
}

[TestMethod]
public void UpdateLessonGrade_Test()
public void UpdateLessonGrade_WhenLessonFailedAndFailingGrade_ReturnUpdatedLesson()
{
const double grade = 70d;
const int lessonId = 12;
var lesson = new Lesson
{
LessonId = lessonId,
Grade = 80d,
IsPassed = false,
};
lessonRepository.GetLesson(lessonId).Returns(lesson);
var module = new Module { MinimumPassingGrade = 90 };
moduleRepository.GetModule(lessonId).Returns(module);

var result = sut.UpdateLesson(lessonId, grade);

Assert.AreEqual(lesson.LessonId, result.LessonId);
Assert.AreEqual(grade, result.Grade);
Assert.IsFalse(result.IsPassed);
}

[TestMethod]
public void UpdateLessonGrade_WhenLessonFailedAndPassingGrade_ReturnUpdatedLesson()
{
const double grade = 70d;
const int lessonId = 12;
var lesson = new Lesson
{
LessonId = lessonId,
Grade = 80d,
IsPassed = false,
};
lessonRepository.GetLesson(lessonId).Returns(lesson);
var module = new Module { MinimumPassingGrade = 70 };
moduleRepository.GetModule(lessonId).Returns(module);

var result = sut.UpdateLesson(lessonId, grade);

Assert.AreEqual(lesson.LessonId, result.LessonId);
Assert.AreEqual(grade, result.Grade);
Assert.IsTrue(result.IsPassed);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,18 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.4.3.1\lib\net45\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="NSubstitute, Version=4.0.0.0, Culture=neutral, PublicKeyToken=92dd2e9066daa5ca, processorArchitecture=MSIL">
<HintPath>..\packages\NSubstitute.4.0.0\lib\net46\NSubstitute.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Threading.Tasks.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.3.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
Expand All @@ -55,6 +66,15 @@
<Compile Include="Services\LessonServiceUnitTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WriteUnitTest\WriteUnitTest.csproj">
<Project>{00A40A05-8314-4F25-A444-46DDEAC3497E}</Project>
<Name>WriteUnitTest</Name>
</ProjectReference>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
Expand Down
Binary file not shown.
Loading