using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Data;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using GalaSoft.MvvmLight.Command;
using Moq;
using SchoolSample.Common;
using SchoolSample.EntityModel;
using SchoolSample.ViewModel;
namespace Test.SchoolSample.ViewModel
{
/// <summary>
///This is a test class for InstructorPageViewModelTest and is intended
///to contain all InstructorPageViewModelTest Unit Tests
///</summary>
[TestClass]
public class InstructorPageViewModelTest
{
private TestContext testContextInstance;
private Mock<ISchoolModel> schoolModelMock;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext
{
get { return testContextInstance; }
set { testContextInstance = value; }
}
#region Additional test attributes
//Use TestInitialize to run code before running each test
[TestInitialize]
public void MyTestInitialize()
{
schoolModelMock = new Mock<ISchoolModel>();
var instructorList = new List<Instructor>
{
new Instructor
{
PersonId = 1,
Name = "Test Instructor One",
Salary = 0,
Courses = new TrackableCollection<Course>
{
new Course
{
CourseId = 1,
InstructorId = 1,
StartDate = DateTime.Today,
EndDate = DateTime.Today,
ClassSize = 10,
Title = "Test Course One"
},
new Course
{
CourseId = 2,
InstructorId = 1,
StartDate = DateTime.Today,
EndDate = DateTime.Today,
ClassSize = 10,
Title = "Test Course Two"
}
}
},
new Instructor
{
PersonId = 2,
Name = "Test Instructor Two",
Salary = 0,
Courses = new TrackableCollection<Course>
{
new Course
{
CourseId = 3,
InstructorId = 2,
StartDate = DateTime.Today,
EndDate = DateTime.Today,
ClassSize = 10,
Title = "Test Course Three"
},
new Course
{
CourseId = 4,
InstructorId = 2,
StartDate = DateTime.Today,
EndDate = DateTime.Today,
ClassSize = 10,
Title = "Test Course Four"
}
}
},
new Instructor
{
PersonId = 3,
Name = "Test Instructor Three",
Salary = 0,
Courses = new TrackableCollection<Course>
{
new Course
{
CourseId = 5,
InstructorId = 3,
StartDate = DateTime.Today,
EndDate = DateTime.Today,
ClassSize = 10,
Title = "Test Course Five"
},
new Course
{
CourseId = 6,
InstructorId = 3,
StartDate = DateTime.Today,
EndDate = DateTime.Today,
ClassSize = 10,
Title = "Test Course Six"
}
}
}
};
schoolModelMock.Setup(n => n.GetInstructorsAsync(It.IsAny<ClientQuery>(), "InstructorPage"))
.Raises(n => n.GetInstructorsCompleted += null,
new ResultsArgs<Instructor>(instructorList, null, false, "InstructorPage"));
schoolModelMock.SetupAllProperties();
}
//Use TestCleanup to run code after each test has run
[TestCleanup]
public void MyTestCleanup()
{
schoolModelMock = null;
}
#endregion
/// <summary>
///A test for InstructorPageViewModel Constructor
///</summary>
[TestMethod]
public void InstructorPageViewModelConstructorTest()
{
InstructorPageViewModel target = new InstructorPageViewModel(schoolModelMock.Object);
schoolModelMock.Verify(n => n.GetInstructorsAsync(It.IsAny<ClientQuery>(), "InstructorPage"), Times.Once());
Assert.IsFalse(target.InstructorFormInEdit);
}
/// <summary>
///A test for AllInstructorsSourceView_CurrentChanged
///</summary>
[TestMethod]
[DeploymentItem("SchoolSample.ViewModel.dll")]
public void AllInstructorsSourceView_CurrentChangedTest()
{
InstructorPageViewModel_Accessor target = new InstructorPageViewModel_Accessor(schoolModelMock.Object);
target.CurrentInstructor = null;
target.AllInstructorsSourceView_CurrentChanged(null, null);
Assert.IsNotNull(target.CurrentInstructor);
}
/// <summary>
///A test for InstructorFormBeginEdit
///</summary>
[TestMethod]
[DeploymentItem("SchoolSample.ViewModel.dll")]
public void InstructorFormBeginEditTest()
{
InstructorPageViewModel_Accessor target = new InstructorPageViewModel_Accessor(schoolModelMock.Object);
target.InstructorFormInEdit = false;
target.InstructorFormBeginEdit();
Assert.IsTrue(target.InstructorFormInEdit);
}
/// <summary>
///A test for InstructorFormCancelEdit
///</summary>
[TestMethod]
[DeploymentItem("SchoolSample.ViewModel.dll")]
public void InstructorFormCancelEditTest()
{
InstructorPageViewModel_Accessor target = new InstructorPageViewModel_Accessor(schoolModelMock.Object);
target.InstructorFormInEdit = true;
target.InstructorFormCancelEdit();
Assert.IsFalse(target.InstructorFormInEdit);
}
/// <summary>
///A test for InstructorFormEndEdit
///</summary>
[TestMethod]
[DeploymentItem("SchoolSample.ViewModel.dll")]
public void InstructorFormEndEditTest()
{
InstructorPageViewModel_Accessor target = new InstructorPageViewModel_Accessor(schoolModelMock.Object);
target.InstructorFormInEdit = true;
target.InstructorFormEndEdit();
Assert.IsFalse(target.InstructorFormInEdit);
}
/// <summary>
///A test for InstructorPageViewModel_PropertyChanged
///</summary>
[TestMethod]
[DeploymentItem("SchoolSample.ViewModel.dll")]
public void InstructorPageViewModel_PropertyChangedTest()
{
InstructorPageViewModel_Accessor target = new InstructorPageViewModel_Accessor(schoolModelMock.Object);
target.InstructorFormInEdit = false;
target.InstructorListIsEnabled = false;
PropertyChangedEventArgs e = new PropertyChangedEventArgs("InstructorFormInEdit");
target.InstructorPageViewModel_PropertyChanged(null, e);
Assert.IsTrue(target.InstructorListIsEnabled);
}
/// <summary>
///A test for OnAddInstructorCommand
///</summary>
[TestMethod]
[DeploymentItem("SchoolSample.ViewModel.dll")]
public void OnAddInstructorCommandTest()
{
InstructorPageViewModel_Accessor target = new InstructorPageViewModel_Accessor(schoolModelMock.Object);
target.OnAddInstructorCommand();
Assert.IsTrue(target.CurrentInstructor.PersonId < 0);
Assert.IsTrue(target.InstructorFormInEdit);
}
/// <summary>
///A test for OnCancelEditInstructorCommand
///</summary>
[TestMethod]
[DeploymentItem("SchoolSample.ViewModel.dll")]
public void OnCancelEditInstructorCommandTest()
{
InstructorPageViewModel_Accessor target = new InstructorPageViewModel_Accessor(schoolModelMock.Object);
target.InstructorFormInEdit = true;
target.OnCancelEditInstructorCommand();
Assert.IsFalse(target.InstructorFormInEdit);
}
/// <summary>
///A test for OnEditCommitInstructorCommand
///</summary>
[TestMethod]
[DeploymentItem("SchoolSample.ViewModel.dll")]
public void OnEditCommitInstructorCommandTest()
{
InstructorPageViewModel_Accessor target = new InstructorPageViewModel_Accessor(schoolModelMock.Object);
target.InstructorFormInEdit = true;
target.OnEditCommitInstructorCommand();
Assert.IsFalse(target.InstructorFormInEdit);
}
/// <summary>
///A test for OnPageLoadedCommand
///</summary>
[TestMethod]
[DeploymentItem("SchoolSample.ViewModel.dll")]
public void OnPageLoadedCommandTest()
{
InstructorPageViewModel_Accessor target = new InstructorPageViewModel_Accessor(schoolModelMock.Object);
schoolModelMock.Object.InstructorsList = null;
schoolModelMock.Object.CurrentInstructor = null;
target.OnPageLoadedCommand();
Assert.IsNotNull(schoolModelMock.Object.InstructorsList);
Assert.IsNotNull(schoolModelMock.Object.CurrentInstructor);
}
/// <summary>
///A test for OnPageUnLoadedCommand
///</summary>
[TestMethod]
[DeploymentItem("SchoolSample.ViewModel.dll")]
public void OnPageUnLoadedCommandTest()
{
InstructorPageViewModel_Accessor target = new InstructorPageViewModel_Accessor(schoolModelMock.Object);
target.OnPageUnLoadedCommand();
Assert.IsNull(schoolModelMock.Object.InstructorsList);
Assert.IsNull(schoolModelMock.Object.CurrentInstructor);
}
/// <summary>
///A test for OnRefreshAllCommand
///</summary>
[TestMethod]
[DeploymentItem("SchoolSample.ViewModel.dll")]
public void OnRefreshAllCommandTest()
{
InstructorPageViewModel_Accessor target = new InstructorPageViewModel_Accessor(schoolModelMock.Object);
target.OnRefreshAllCommand();
schoolModelMock.Verify(n => n.GetInstructorsAsync(It.IsAny<ClientQuery>(), "InstructorPage"),
Times.Exactly(2));
}
/// <summary>
///A test for OnRefreshInstructorCommand
///</summary>
[TestMethod]
[DeploymentItem("SchoolSample.ViewModel.dll")]
public void OnRefreshInstructorCommandTest()
{
InstructorPageViewModel_Accessor target = new InstructorPageViewModel_Accessor(schoolModelMock.Object);
target.OnRefreshInstructorCommand();
schoolModelMock.Verify(n => n.GetInstructorByIdAsync(It.IsAny<int>()), Times.Once());
}
/// <summary>
///A test for OnSubmitAllChangeCommand
///</summary>
[TestMethod]
[DeploymentItem("SchoolSample.ViewModel.dll")]
public void OnSubmitAllChangeCommandTest()
{
InstructorPageViewModel_Accessor target = new InstructorPageViewModel_Accessor(schoolModelMock.Object);
target.OnSubmitAllChangeCommand();
schoolModelMock.Verify(n => n.SaveInstructorChangesAsync(true), Times.Once());
}
/// <summary>
///A test for OnSubmitInstructorChangeCommand
///</summary>
[TestMethod]
[DeploymentItem("SchoolSample.ViewModel.dll")]
public void OnSubmitInstructorChangeCommandTest()
{
InstructorPageViewModel_Accessor target = new InstructorPageViewModel_Accessor(schoolModelMock.Object);
target.OnSubmitInstructorChangeCommand();
schoolModelMock.Verify(n => n.SaveInstructorChangesAsync(false), Times.Once());
}
/// <summary>
///A test for _schoolModel_GetInstructorByIdCompleted
///</summary>
[TestMethod]
[DeploymentItem("SchoolSample.ViewModel.dll")]
public void _schoolModel_GetInstructorByIdCompletedTest()
{
InstructorPageViewModel_Accessor target = new InstructorPageViewModel_Accessor(schoolModelMock.Object);
ResultArgs<Instructor> e = new ResultArgs<Instructor>(
new Instructor
{
PersonId = 1,
Name = "Test Instructor One",
Salary = 0
}, null, false, null);
target._schoolModel_GetInstructorByIdCompleted(null, e);
Assert.IsTrue(target.CurrentInstructor.Courses.Count == 0);
}
/// <summary>
///A test for _schoolModel_GetInstructorsCompleted
///</summary>
[TestMethod]
[DeploymentItem("SchoolSample.ViewModel.dll")]
public void _schoolModel_GetInstructorsCompletedTest()
{
InstructorPageViewModel_Accessor target = new InstructorPageViewModel_Accessor(schoolModelMock.Object);
ResultsArgs<Instructor> e = new ResultsArgs<Instructor>(new List<Instructor>(), null, false,
"InstructorPage");
target._schoolModel_GetInstructorsCompleted(null, e);
Assert.IsTrue(target.AllInstructors.Count == 0);
Assert.IsNull(target.CurrentInstructor);
}
/// <summary>
///A test for _schoolModel_SaveInstructorChangesCompleted
///</summary>
[TestMethod]
[DeploymentItem("SchoolSample.ViewModel.dll")]
public void _schoolModel_SaveInstructorChangesCompletedTest()
{
InstructorPageViewModel_Accessor target = new InstructorPageViewModel_Accessor(schoolModelMock.Object);
ResultArgs<string> e = new ResultArgs<string>(string.Empty, null, false, null);
target._schoolModel_SaveInstructorChangesCompleted(null, e);
schoolModelMock.Verify(n => n.GetInstructorsAsync(It.IsAny<ClientQuery>(), "InstructorPage"),
Times.Exactly(2));
}
/// <summary>
///A test for AllInstructors
///</summary>
[TestMethod]
[DeploymentItem("SchoolSample.ViewModel.dll")]
public void AllInstructorsTest()
{
InstructorPageViewModel_Accessor target = new InstructorPageViewModel_Accessor(schoolModelMock.Object);
ObservableCollection<Instructor> expected = new ObservableCollection<Instructor>();
target.AllInstructors = expected;
ObservableCollection<Instructor> actual = target.AllInstructors;
Assert.AreEqual(expected, actual);
}
/// <summary>
///A test for AllInstructorsSource
///</summary>
[TestMethod]
[DeploymentItem("SchoolSample.ViewModel.dll")]
public void AllInstructorsSourceTest()
{
InstructorPageViewModel_Accessor target = new InstructorPageViewModel_Accessor(schoolModelMock.Object);
CollectionViewSource expected = new CollectionViewSource();
target.AllInstructorsSource = expected;
CollectionViewSource actual = target.AllInstructorsSource;
Assert.AreEqual(expected, actual);
}
/// <summary>
///A test for CurrentInstructor
///</summary>
[TestMethod]
[DeploymentItem("SchoolSample.ViewModel.dll")]
public void CurrentInstructorTest()
{
InstructorPageViewModel_Accessor target = new InstructorPageViewModel_Accessor(schoolModelMock.Object);
Instructor expected = new Instructor();
target.CurrentInstructor = expected;
Instructor actual = target.CurrentInstructor;
Assert.AreEqual(expected, actual);
}
/// <summary>
///A test for CurrentInstructorHasErrors
///</summary>
[TestMethod]
public void CurrentInstructorHasErrorsTest()
{
InstructorPageViewModel target = new InstructorPageViewModel(schoolModelMock.Object);
target.CurrentInstructorHasErrors = true;
bool actual = target.CurrentInstructorHasErrors;
Assert.IsTrue(actual);
}
/// <summary>
///A test for InstructorFormInEdit
///</summary>
[TestMethod]
[DeploymentItem("SchoolSample.ViewModel.dll")]
public void InstructorFormInEditTest()
{
InstructorPageViewModel_Accessor target = new InstructorPageViewModel_Accessor(schoolModelMock.Object);
target.InstructorFormInEdit = true;
bool actual = target.InstructorFormInEdit;
Assert.IsTrue(actual);
}
/// <summary>
///A test for InstructorListIsEnabled
///</summary>
[TestMethod]
[DeploymentItem("SchoolSample.ViewModel.dll")]
public void InstructorListIsEnabledTest()
{
InstructorPageViewModel_Accessor target = new InstructorPageViewModel_Accessor(schoolModelMock.Object);
target.InstructorListIsEnabled = true;
bool actual = target.InstructorListIsEnabled;
Assert.IsTrue(actual);
}
/// <summary>
///A test for AddInstructorCommand
///</summary>
[TestMethod]
public void AddInstructorCommandTest()
{
InstructorPageViewModel target = new InstructorPageViewModel(schoolModelMock.Object);
RelayCommand actual = target.AddInstructorCommand;
Assert.IsNotNull(actual);
}
/// <summary>
///A test for CancelAllChangeCommand
///</summary>
[TestMethod]
public void CancelAllChangeCommandTest()
{
InstructorPageViewModel target = new InstructorPageViewModel(schoolModelMock.Object);
RelayCommand actual = target.CancelAllChangeCommand;
Assert.IsNotNull(actual);
}
/// <summary>
///A test for CancelEditInstructorCommand
///</summary>
[TestMethod]
public void CancelEditInstructorCommandTest()
{
InstructorPageViewModel target = new InstructorPageViewModel(schoolModelMock.Object);
RelayCommand actual = target.CancelEditInstructorCommand;
Assert.IsNotNull(actual);
}
/// <summary>
///A test for CancelInstructorChangeCommand
///</summary>
[TestMethod]
public void CancelInstructorChangeCommandTest()
{
InstructorPageViewModel target = new InstructorPageViewModel(schoolModelMock.Object);
RelayCommand actual = target.CancelInstructorChangeCommand;
Assert.IsNotNull(actual);
}
/// <summary>
///A test for DeleteInstructorCommand
///</summary>
[TestMethod]
public void DeleteInstructorCommandTest()
{
InstructorPageViewModel target = new InstructorPageViewModel(schoolModelMock.Object);
RelayCommand actual = target.DeleteInstructorCommand;
Assert.IsNotNull(actual);
}
/// <summary>
///A test for EditCommitInstructorCommand
///</summary>
[TestMethod]
public void EditCommitInstructorCommandTest()
{
InstructorPageViewModel target = new InstructorPageViewModel(schoolModelMock.Object);
RelayCommand actual = target.EditCommitInstructorCommand;
Assert.IsNotNull(actual);
}
/// <summary>
///A test for PageLoadedCommand
///</summary>
[TestMethod]
public void PageLoadedCommandTest()
{
InstructorPageViewModel target = new InstructorPageViewModel(schoolModelMock.Object);
RelayCommand actual = target.PageLoadedCommand;
Assert.IsNotNull(actual);
}
/// <summary>
///A test for PageUnLoadedCommand
///</summary>
[TestMethod]
public void PageUnLoadedCommandTest()
{
InstructorPageViewModel target = new InstructorPageViewModel(schoolModelMock.Object);
RelayCommand actual = target.PageUnLoadedCommand;
Assert.IsNotNull(actual);
}
/// <summary>
///A test for RefreshAllCommand
///</summary>
[TestMethod]
public void RefreshAllCommandTest()
{
InstructorPageViewModel target = new InstructorPageViewModel(schoolModelMock.Object);
RelayCommand actual = target.RefreshAllCommand;
Assert.IsNotNull(actual);
}
/// <summary>
///A test for RefreshInstructorCommand
///</summary>
[TestMethod]
public void RefreshInstructorCommandTest()
{
InstructorPageViewModel target = new InstructorPageViewModel(schoolModelMock.Object);
RelayCommand actual = target.RefreshInstructorCommand;
Assert.IsNotNull(actual);
}
/// <summary>
///A test for SubmitAllChangeCommand
///</summary>
[TestMethod]
public void SubmitAllChangeCommandTest()
{
InstructorPageViewModel target = new InstructorPageViewModel(schoolModelMock.Object);
RelayCommand actual = target.SubmitAllChangeCommand;
Assert.IsNotNull(actual);
}
/// <summary>
///A test for SubmitInstructorChangeCommand
///</summary>
[TestMethod]
public void SubmitInstructorChangeCommandTest()
{
InstructorPageViewModel target = new InstructorPageViewModel(schoolModelMock.Object);
RelayCommand actual = target.SubmitInstructorChangeCommand;
Assert.IsNotNull(actual);
}
}
}