public void ShouldCheckTypeOfInstanceResultAfterEditFromPatientsController_WithFakeRepository()
        {
            _patientsController = new PatientsController(_fakePatientRepository);

            var expectedType = typeof(ActionResult);
            var value        = _patientsController.Edit(new Patient());

            Assert.IsInstanceOfType(value, expectedType);
        }
Пример #2
0
        public void Edit(int?id)
        {
            // Arrange
            PatientsController controller = new PatientsController();

            // Act
            ViewResult result = controller.Edit(id) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
        public void ShouldCheckResultFromPatientsControllerEdit_WithMock()
        {
            var patient = new Patient();
            var service = new Mock <IPatientRepository>();

            service.Setup(x => x.GetPatientById(1)).Returns(patient);
            _patientsController = new PatientsController(service.Object);

            var expected = patient;
            var result   = _patientsController.Edit(1);
            var actual   = ((ViewResult)result).Model as Patient;

            Assert.AreEqual(actual, expected);
        }
Пример #4
0
using UTSMedicalSystem.FrontEnd.Controllers;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using UTSMedicalSystem.FrontEnd.Data;
using System.Threading.Tasks;
using System;
using UTSMedicalSystem.FrontEnd.Models;
using System.Diagnostics.Contracts;
using System.Linq;

namespace UnitTestProject.Testing
{
    [TestClass]
    public class ControllerTesting : IDisposable
    {
        protected readonly MedicalSystemContext _context;

        public ControllerTesting()
        {
            var options = new DbContextOptionsBuilder<MedicalSystemContext>()
                .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                .Options;
            _context = new MedicalSystemContext(options);
            var users = new[]{
                new User { ID = 1, AspNetUserId = "1" ,FirstName = "Alex", LastName ="Alex", DOB = "01/01/2001", UTSID = "11111111", History = "Broken leg", Role = "Patient"} ,
                new User { ID = 2, AspNetUserId = "2", FirstName = "Ben", LastName = "Bruh", DOB = "02/02/2002", UTSID = "22222222", History = "Broken arm", Role = "Patient" },
                new User { ID = 3, AspNetUserId = "3", FirstName = "Carl", LastName = "Car", DOB = "03/03/2003", UTSID = "33333333", History = "Heart transpant", Role = "Patient" },
                new User { ID = 4, AspNetUserId = "4", FirstName = "Daniel", LastName = "Doug", DOB = "04/04/2004", UTSID = "44444444", History = "Dizzy Spells", Role = "Patient" },
                new User { ID = 5, AspNetUserId = "5", FirstName = "Eggie", LastName = "Excellent", DOB = "05/05/2005", UTSID = "55555555", History = "Amputated arm", Role = "Patient" },
                new User { ID = 6, AspNetUserId = "6", FirstName = "Freddie", LastName = "Frog", DOB = "06/06/2006", UTSID = "66666666", History = "Amputated leg", Role = "Receptionist" },
                new User { ID = 7, AspNetUserId = "7", FirstName = "Gabbie", LastName = "Goat", DOB = "07/07/2007", UTSID = "77777777", History = "Amputated head", Role = "Doctor" },
            };
            _context.Users.AddRange(users);
            _context.Appointments.AddRange(new Appointment { ID = 1, Notes = "Fever", Location = "UTS", DoctorID = 7, PatientID = 1, Patient = users.FirstOrDefault() });
            _context.SaveChanges();
            _context.Database.EnsureCreated();
        }

        
        //Testing HomeController
        [TestMethod]
        public void TestingHCIdexViewType()
        {
            //Arrange
            var controller = new HomeController();

            //Act
            var result = controller.Index();
 
            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result,typeof(ViewResult));
        }

         [TestMethod]
        public void TestingHCAboutViewType()
        {
            //Arrange
            var controller = new HomeController();

            //Act
            var result = controller.About();

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }

         [TestMethod]
        public void TestingHCContactViewType()
        {
            //Arrange
            var controller = new HomeController();

            //Act
            var result = controller.Contact();

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }

        //Testing PatientController
          [TestMethod]
        public async Task TestingPCDetailsViewTypeAsync()
        {
            //Arrange
            var controller = new PatientsController(_context);

            //Act
            var result = await controller.Details(1);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        } 

          [TestMethod]
        public async Task TestingPCDetailsViewErrorAsync()
        {
            //Arrange
            var controller = new PatientsController(_context);
            
            //act
            var result = await controller.Details(null);   

            //Assert
            Assert.IsNotNull(result);
       
            Assert.AreEqual(typeof(NotFoundResult),result.GetType());
        } 

        [TestMethod]
        public async Task TestingPCDetailsViewErrorIDAsync()
        {
            //Arrange
            var controller = new PatientsController(_context);

            //Act
            var result = await controller.Details(10);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(NotFoundResult), result.GetType());
        } 


        [TestMethod]
        public async Task TestingPCEditViewErrorAsync()
        {
            //Arrange
            var controller = new PatientsController(_context);

            //act
            var result = await controller.Edit(null);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(NotFoundResult), result.GetType());
        }

        [TestMethod]
        public async Task TestingPCEditViewErrorIDAsync()
        {
            //Arrange
            var controller = new PatientsController(_context);

            //Act
            var result = await controller.Edit(10);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(NotFoundResult), result.GetType());
        }

        [TestMethod]
        public async Task TestingPCDeleteViewTypeAsync()
        {
            //Arrange
            var controller = new PatientsController(_context);

            //Act
            var result = await controller.Delete(1);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }

        [TestMethod]
        public async Task TestingPCDeleteViewErrorAsync()
        {
            //Arrange
            var controller = new PatientsController(_context);

            //act
            var result = await controller.Delete(null);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(NotFoundResult), result.GetType());
        }

        [TestMethod]
        public async Task TestingPCDeleteViewErrorIDAsync()
        {
            //Arrange
            var controller = new PatientsController(_context);

            //Act
            var result = await controller.Delete(10);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(NotFoundResult), result.GetType());
        }


        //Testing Appointment Controller 
        [TestMethod]
        public void TestingACGetNameIDInvaild()
        {
            //Arrange
            var controller = new AppointmentsController(_context);

            //Act
            var result = controller.getName(999999);

            //Assert
            Assert.AreEqual("Error: Invalid User",result);
        }
        [TestMethod]
        public void TestingACGetNameIDVaild()
        {
            //Arrange
            var controller = new AppointmentsController(_context);

            //Act
            var result = controller.getName(1);

            //Assert
            Assert.AreEqual("Alex Alex", result);
        }

        [TestMethod]
        public void TestingACGetNameIDVaildDoctor()
        {
            //Arrange
            var controller = new AppointmentsController(_context);

            //Act
            var result = controller.getName(7);

            //Assert
            Assert.AreEqual("Dr Goat", result);
        }

         [TestMethod]
        public async Task TestingACPatientDetailsViewTypeAsync()
        {
            //Arrange
            var controller = new AppointmentsController(_context);

            //Act
            var result = await controller.PatientDetails(1);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }

        [TestMethod]
        public async Task TestingACPatientDetailsViewErrorAsync()
        {
            //Arrange
            var controller = new AppointmentsController(_context);

            //act
            var result = await controller.PatientDetails(null);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(NotFoundResult), result.GetType());
        }

        [TestMethod]
        public async Task TestingACPatientDetailsViewErrorIDAsync()
        {
            //Arrange
            var controller = new AppointmentsController(_context);

            //Act
            var result = await controller.PatientDetails(10);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(NotFoundResult), result.GetType());
        }

        [TestMethod]
        public async Task TestingACDetailsViewTypeAsync()
        {
            //Arrange
            var controller = new AppointmentsController(_context);

            //Act
            var result = await controller.Details(1);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }

        [TestMethod]
        public async Task TestingACDetailsViewErrorAsync()
        {
            //Arrange
            var controller = new AppointmentsController(_context);

            //act
            var result = await controller.Details(null);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(NotFoundResult), result.GetType());
        }

        [TestMethod]
        public async Task TestingACDetailsViewErrorIDAsync()
        {
            //Arrange
            var controller = new AppointmentsController(_context);

            //Act
            var result = await controller.Details(3);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(NotFoundResult), result.GetType());
        }
         [TestMethod]
        public async Task TestingACDetailsViewErrorID2Async()
        {
            //Arrange
            var controller = new AppointmentsController(_context);

            //Act
            var result = await controller.Details(1121);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(NotFoundResult), result.GetType());
        }

        [TestMethod]
        public async Task TestingACEditViewTypeAsync()
        {
            //Arrange
            var controller = new AppointmentsController(_context);

            //Act
            var result = await controller.Edit(1);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }

        [TestMethod]
        public async Task TestingACEditViewErrorAsync()
        {
            //Arrange
            var controller = new AppointmentsController(_context);

            //act
            var result = await controller.Edit(null);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(NotFoundResult), result.GetType());
        }

        [TestMethod]
        public async Task TestingACEditViewErrorIDAsync()
        {
            //Arrange
            var controller = new AppointmentsController(_context);

            //Act
            var result = await controller.Edit(3);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(NotFoundResult), result.GetType());
        }
        [TestMethod]
        public async Task TestingACEditViewErrorID2Async()
        {
            //Arrange
            var controller = new AppointmentsController(_context);

            //Act
            var result = await controller.Edit(1121);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(NotFoundResult), result.GetType());
        }

        [TestMethod]
        public async Task TestingACDeleteViewTypeAsync()
        {
            //Arrange
            var controller = new AppointmentsController(_context);

            //Act
            var result = await controller.Delete(1);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }

        [TestMethod]
        public async Task TestingACDeleteViewErrorAsync()
        {
            //Arrange
            var controller = new AppointmentsController(_context);

            //act
            var result = await controller.Delete(null);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(NotFoundResult), result.GetType());
        }

        [TestMethod]
        public async Task TestingACDeleteViewErrorIDAsync()
        {
            //Arrange
            var controller = new AppointmentsController(_context);

            //Act
            var result = await controller.Delete(3);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(NotFoundResult), result.GetType());
        }
        [TestMethod]
        public async Task TestingACDeleteViewErrorID2Async()
        {
            //Arrange
            var controller = new AppointmentsController(_context);

            //Act
            var result = await controller.Delete(1121);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(NotFoundResult), result.GetType());
        }

        public void Dispose()
        {
            _context.Database.EnsureDeleted();
            _context.Dispose();
        }

     
    }
}