public void InstanceIsAssignableToStaticType() { ModelBase act = new ModelBase(); IModel iModel; // MSTest does not support this case. // NUnit Assert.That(act, Is.InstanceOf <IModel>(), () => "Some context"); // Some context // Expected: instance of <IModel> // But was: <ModelBase> // XUnit iModel = XUnitAssert.IsAssignableFrom <IModel>(act); // Assert.IsAssignableFrom() Failure // Expected: typeof(IModel) // Actual: typeof(ModelBase) // Fluent iModel = act.Should().BeAssignableTo <IModel>("SOME REASONS").Which; // Expected iModel = act to be assignable to IModel because SOME REASONS, but ModelBase is not. // Shouldly iModel = act.ShouldBeAssignableTo <IModel>("Some context"); // act // should be assignable to // IModel // but was // ModelBase // // Additional Info: // Some context }
public async Task RegisterWhenDataInvalid_ExpectedNotChangeBD() { //Arrange var userManager = FakeTestingService.MockUserManager <User>(_users); userManager.Setup(_ => _.CreateAsync(It.IsAny <User>(), It.IsAny <string>())).ReturnsAsync(IdentityResult.Failed()); var signInManager = FakeTestingService.MockSightInManager <User>(userManager.Object); var accaunt = new preparation.Controllers.AccountController(userManager.Object, signInManager.Object); var regModel = new UserRegisterViewModel() { Address = "test", AgreementConfirm = false, Country = "test", Email = "test", FirstName = "test", Password = "******", Username = "******", Surname = "test", PasswordConfirm = "test" }; string testRedirect = "/"; //Actual var actual = await accaunt.Register(regModel, testRedirect); //Assert Assert.Equal(2, _users.Count); var model = Assert.IsType <ViewResult>(actual); Assert.IsAssignableFrom <UserRegisterViewModel>(model.ViewData.Model); }
public void FindSeatsTests_BookingId_NotNull() { var result = _findRoomsController.FindRooms("tenantName", 1, 1); // Assert var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <IEnumerable <BookingModel> >(viewResult.Model); Assert.Single(model); }
public void FindSeatsTests_EventId_NotNull() { var result = _findSeatsController.FindSeats(1); // Assert var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <IEnumerable <EventModel> >(viewResult.Model); Assert.Equal(1, model.Count()); }
public void Index_ReturnsView() { // Act var result = _eventsController.Index("testTenant"); // Assert var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <IEnumerable <EventModel> >(viewResult.ViewData.Model); Assert.Equal(2, model.Count()); }
public async void GamesController_Index_NoGames() { //Arrange var mockGameRepository = new MockGameRepository().MockGetGames(new List <Game>()); var controller = new GamesController(mockGameRepository.Object); //act var result = await controller.Index(); //assert Assert.IsAssignableFrom <ActionResult <IEnumerable <Game> > >(result); mockGameRepository.VerifyGetGames(Times.Once()); }
public async Task GetTopWhenDataIsnotEmpty() { //Arrange var goods = new[] { new Good() { Price = 2.12m, Product = new Preparation() { Name = "_world_" } }, new Good() { Price = 12.2m, Product = new Preparation() { Name = "hello_world" } }, }; IEnumerable <IEnumerable <IProduct> > expected = new[] { new[] { goods[0] }, new[] { goods[1] }, }; var mok = new Mock <IStreinger>(); mok.Setup(m => m.Goods()) .ReturnsAsync(goods); var algorighm = new Mock <TopAlgorithm>(); algorighm.Setup(a => a.Top(It.IsAny <IEnumerable <IEnumerable <IProduct> > >())) .Returns(expected); var seachController = new preparation.Controllers.SearchController(mok.Object, algorighm.Object); //Actual var resp = await seachController.Index(); //Assert var viewResult = Assert.IsType <ViewResult>(resp); IEnumerable <IEnumerable <IProduct> > model = Assert.IsAssignableFrom <IEnumerable <IEnumerable <IProduct> > >(viewResult.ViewData.Model); Assert.Equal(expected, model); }
public async void GamesController_Game_Delete_Confirmed() { //Arrange var mockGameRepository = new MockGameRepository().MockDeleteGame(); var controller = new GamesController(mockGameRepository.Object); //act var result = await controller.DeleteConfirmed(1); //assert Assert.IsAssignableFrom <ActionResult <Game> >(result); // mockGameRepository.VerifyGetGameByID(Times.Once()); mockGameRepository.VerifyDeleteGame(Times.Once()); }
public void GetByIdSpeciality() { // Arrange var config = new MapperConfiguration(cfg => cfg.CreateMap <Speciality, SpecialityDTO>()); var mock = new Mock <IUnitOfWork>(); mock.Setup(unitOfWork => unitOfWork.Specialities.Get(1)).Returns(GetByIdTestSpecialityDTO()); var manager = new SpecialityManager(mock.Object, new AttributeValidator(), new Mapper(config)); // Act var result = manager.GetById(1); // Arrange var viewResult = Assert.IsType <SpecialityDTO>(result); var model = Assert.IsAssignableFrom <SpecialityDTO>(viewResult); Assert.Equal(GetByIdTestSpecialityDTO().Id, model.Id); }
public void GetAllReturnsAViewResultWithAListOfSpecialities() { // Arrange var config = new MapperConfiguration(cfg => cfg.CreateMap <Speciality, SpecialityDTO>()); var mock = new Mock <IUnitOfWork>(); mock.Setup(unitOfWork => unitOfWork.Specialities.GetAll()).Returns(GetAllTestSpecialityDTO()); var manager = new SpecialityManager(mock.Object, new AttributeValidator(), new Mapper(config)); // Act var result = manager.GetAll(); // Assert var viewResult = Assert.IsType <List <SpecialityDTO> >(result); var model = Assert.IsAssignableFrom <IEnumerable <SpecialityDTO> >(viewResult); Assert.Equal(GetAllTestSpecialityDTO().Count, model.Count()); }
public async void GamesController_Edit_Game() { //Arrange var mockGame = new Game() { GameId = 1 }; var mockGameRepository = new MockGameRepository().MockGetGameByID(mockGame); var controller = new GamesController(mockGameRepository.Object); //act var result = await controller.Edit(1); //Assert Assert.IsAssignableFrom <ActionResult <Game> >(result); mockGameRepository.VerifyGetGameByID(Times.Once()); }
public async Task SearchWhenProductExists() { //Arrange var goods = new[] { new Good() { Price = 2.12m, Product = new Preparation() { Name = "_world_" } }, new Good() { Price = 12.2m, Product = new Preparation() { Name = "hello_world" } }, }; var mok = new Mock <IStreinger>(); mok.Setup(m => m.Goods()) .ReturnsAsync(goods); var seachController = new preparation.Controllers.SearchController(mok.Object, null); IEnumerable <IEnumerable <IProduct> > expected = new[] { new[] { goods[0] }, new[] { goods[1] }, }; //Actual var resp = await seachController.Search("_world"); //Assert var viewResult = Assert.IsType <ViewResult>(resp); IEnumerable <IEnumerable <IProduct> > model = Assert.IsAssignableFrom <IEnumerable <IEnumerable <IProduct> > >(viewResult.ViewData.Model); Assert.Equal(expected, model); }
public void InstanceIsAssignableToTypeReference() { ModelBase act = new ModelBase(); Type t = typeof(IModel); // MSTest MSTestAssert.IsInstanceOfType(act, t, "Some context"); // Assert.IsInstanceOfType failed. Some context Expected type:<IModel>. Actual type:<ModelBase>. // NUnit Assert.That(act, Is.InstanceOf(t), () => "Some context"); // Some context // Expected: instance of <IModel> // But was: <ModelBase> // XUnit XUnitAssert.IsAssignableFrom(t, act); // Assert.IsAssignableFrom() Failure // Expected: typeof(IModel) // Actua: typeof(ModelBase) // Fluent act.Should().BeAssignableTo(t, "SOME REASONS"); // Expected act to be assignable to IModel because SOME REASONS, but ModelBase is not. // Shouldly act.ShouldBeAssignableTo(t, "Some context"); // act // should be assignable to // IModel // but was // ModelBase // // Additional Info: // Some context }
public async void InsertPatient_ValidPatient_InsertionOK(string name, string lastname, string email) { Guid id = Guid.NewGuid(); string testId = string.Empty; try { testId = Test.AddTest( new testDefinition { name = "Insert a Patient", description = "This test should insert a patient", storyName = "Insert a Patient", featureName = "Positive Tests", epicName = "Unit Tests" }); // Arrange Test.AddStep(new step { description = "Arrange", name = "Step 1: Arrange" }); PatientViewModel patientToInsert = new PatientViewModel { Email = email, Id = id, Surname = lastname, Name = name }; Patient mappedPatientToInsert = this.mapper.Map <Patient>(patientToInsert); this.mockPatientRepository.Setup(repo => repo.Add(It.Is <Patient>(p => p.Equals(mappedPatientToInsert)))); PatientController sut = this.sutBuilder.WithRepository(this.mockRepositories.Object); Test.StopStep(Status.passed); // Act Test.AddStep( new step { description = "Insert patient", name = "Step 2: Act", listParamenters = new List <Parameter> { new Parameter { name = "Email", value = patientToInsert.Email }, new Parameter { name = "Name", value = patientToInsert.Name }, new Parameter { name = "Surname", value = patientToInsert.Surname }, new Parameter { name = "Id", value = patientToInsert.Id.ToString() } } }); var result = await sut.CreatePatient(patientToInsert); Test.StopStep(Status.passed); // Assert Test.AddStep(new step { description = "Check if the patient was inserted", name = "Step 3: Assert" }); this.mockRepositories.Verify(); var viewResult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsAssignableFrom <PatientViewModel>(viewResult.Value); // we expect the MRN to be this string patientToInsert.MedicalNumber = MockedMedicalRecordNumber; Assert.Equal(JsonConvert.SerializeObject(patientToInsert), JsonConvert.SerializeObject(model)); Test.StopStep(Status.passed); Test.StopTest(testId, Status.passed, "Test success", "Passed"); } catch (Exception ex) { Test.StopStep(Status.failed); Test.StopTest(testId, Status.passed, "Test failed", ex.ToString()); Assert.True(false); } }
public async Task GetPatients_Should_Return_Patient_Information() { string testId = string.Empty; try { testId = Test.AddTest( new testDefinition { name = "Get list of patients", description = "This test should return a patient information", storyName = "Patient Retrieve", featureName = "Positive Tests", epicName = "Unit Tests" }); // Arrange Test.AddStep(new step { description = "Arrange", name = "Step 1: Arrange" }); this.mockPatientRepository.Setup(repo => repo.Get(It.IsAny <Guid>())) .ReturnsAsync(this.listOfPatients[1]); PatientController sut = this.sutBuilder.WithRepository(this.mockRepositories.Object); Test.StopStep(Status.passed); // Act Test.AddStep( new step { description = " Get patient information", name = "Step 2: Act", listParamenters = new List <Parameter> { new Parameter { name = "Patient ID", value = this.listOfPatients[1].Id.ToString() } } }); var result = await sut.GetPatient(this.listOfPatients[1].Id); Test.StopStep(Status.passed); // Assert Test.AddStep( new step { description = "Check if the patient information returned is correct", name = "Step 3: Assert" }); var viewResult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsAssignableFrom <PatientViewModel>(viewResult.Value); Assert.Equal(this.listOfPatients[1].Email, model.Email); Assert.Equal(this.listOfPatients[1].Name, model.Name); Assert.Equal(this.listOfPatients[1].Surname, model.Surname); Assert.Equal(this.listOfPatients[1].MedicalNumber, model.MedicalNumber); Assert.Equal(this.listOfPatients[1].Id, model.Id); Test.StopStep(Status.passed); Test.StopTest(testId, Status.passed, "Test success", "Passed"); } catch (Exception ex) { Test.StopStep(Status.failed); Test.StopTest(testId, Status.passed, "Test failed", ex.ToString()); Assert.True(false); } }
public async Task GetAllPatients_Paged_Should_Return_List_Of_Patients_After_Last_Page() { int totalElements = 90; int page = 5; int elementsPerPage = 18; string testId = string.Empty; IQueryable <Patient> list = this.GetPatientList(totalElements); try { testId = Test.AddTest( new testDefinition { name = "Get list of patients", description = "This test should return a list of patients", storyName = "Patient Retrieve", featureName = "Positive Tests", epicName = "Unit Tests" }); // Arrange Test.AddStep(new step { description = "Arrange", name = "Step 1: Arrange" }); this.mockPatientRepository .Setup(repo => repo.GetAllWithPaginationPatients(It.IsAny <int>(), It.IsAny <int>())).ReturnsAsync( new PagedList <Patient>(list, page + 1, elementsPerPage)); PatientController sut = this.sutBuilder.WithRepository(this.mockRepositories.Object); Test.StopStep(Status.passed); // Act Test.AddStep( new step { description = $" Get all the patients of page {page}, just {elementsPerPage} items", name = "Step 2: Act" }); var result = await sut.GetAllPatients(page, 18); Test.StopStep(Status.passed); // Assert Test.AddStep( new step { description = "Check if the number the patients returned is correct", name = "Step 3: Assert" }); var viewResult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsAssignableFrom <ExtendedPagedList <PatientViewModel> >(viewResult.Value); Assert.Equal(0, model.NumberOfElements); Assert.Equal(page, model.Number); Assert.Equal(totalElements, model.TotalElements); // the list shall be empty Assert.False(model.Content.Any()); Test.StopStep(Status.passed); Test.StopTest(testId, Status.passed, "Test success", "Passed"); } catch (Exception ex) { Test.StopStep(Status.failed); Test.StopTest(testId, Status.passed, "Test failed", ex.ToString()); Assert.True(false, ex.ToString()); } }