public void CreatePatientDocument_GivenValidArguments_IsMadePersistent()
        {
            bool isPersistent = false;
            var bytes = new byte[] { 0, 0, 0 };
            var hashingUtility = new Mock<IHashingUtility>();
            hashingUtility.Setup(m => m.ComputeHash(bytes)).Returns("XXXXXXXXXXX");

            var patientDocumentRepositoryMock = new Mock<IPatientDocumentRepository> ();
            patientDocumentRepositoryMock
                .Setup ( p => p.MakePersistent ( It.IsAny<PatientDocument> () ) )
                .Callback ( () => isPersistent = true );
            var patientDocumentFactory = new PatientDocumentFactory (
                patientDocumentRepositoryMock.Object, hashingUtility.Object );
            var patient = new Mock<Patient> ();
            var patientDocumentType = new Mock<PatientDocumentType> ();

            patientDocumentFactory.CreatePatientDocument (
                patient.Object,
                patientDocumentType.Object,
                bytes,
                "filename"
                );

            Assert.IsTrue ( isPersistent );
        }
        public void CreatePatientDocument_GivenValidArguments_EntityIsEditable()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);
                var bytes = new byte[] {0, 0, 0};
                var patientDocumentRepositoryMock = new Mock<IPatientDocumentRepository>();
                var hashingUtility = new Mock<IHashingUtility>();
                hashingUtility.Setup(m => m.ComputeHash(bytes)).Returns("XXXXXXXXXXX");

                var patientDocumentFactory = new PatientDocumentFactory(
                    patientDocumentRepositoryMock.Object, hashingUtility.Object);
                var patient = new Mock<Patient>();
                var patientDocumentType = new Mock<PatientDocumentType>();

                PatientDocument patientDocument = patientDocumentFactory.CreatePatientDocument(
                    patient.Object,
                    patientDocumentType.Object,
                    bytes,
                    "filename");

                patientDocument.ReviseOtherDocumentTypeName ( "Other"  );
            }
        }
        public void CreatePatientDocument_BlankFileName_ThrowsException()
        {
            var bytes = new byte[] { 0, 0, 0 };
            var hashingUtility = new Mock<IHashingUtility>();
            hashingUtility.Setup(m => m.ComputeHash(bytes)).Returns("XXXXXXXXXXX");

            var patientDocumentRepositoryMock = new Mock<IPatientDocumentRepository> ();
            var patientDocumentFactory = new PatientDocumentFactory (
                patientDocumentRepositoryMock.Object, hashingUtility.Object );
            var patient = new Mock<Patient> ();
            var patientDocumentType = new Mock<PatientDocumentType> ();

            patientDocumentFactory.CreatePatientDocument (
                patient.Object,
                patientDocumentType.Object,
                bytes,
                ""
                );
        }
        public void CreatePatientDocument_GivenValidArguments_Succeeds()
        {
            var bytes = new byte[] { 0, 0, 0 };
            var patientDocumentRepositoryMock = new Mock<IPatientDocumentRepository> ();
            var hashingUtility = new Mock<IHashingUtility> ();
            hashingUtility.Setup ( m => m.ComputeHash ( bytes ) ).Returns ( "XXXXXXXXXXX" );
            var patientDocumentFactory = new PatientDocumentFactory (
                patientDocumentRepositoryMock.Object, hashingUtility.Object  );
            var patient = new Mock<Patient> ();
            var patientDocumentType = new Mock<PatientDocumentType> ();

            var patientDocument = patientDocumentFactory.CreatePatientDocument (
                patient.Object,
                patientDocumentType.Object,
                bytes,
                "filename"
               );

            Assert.IsNotNull ( patientDocument );
        }
        public void DestroyPatientDocument_GivenPatientDocument_Succeeds()
        {
            var bytes = new byte[] { 0, 0, 0 };
            var hashingUtility = new Mock<IHashingUtility>();
            hashingUtility.Setup(m => m.ComputeHash(It.IsAny<byte[]>())).Returns("XXXXXXXXXXX");

            var patientDocumentRepositoryMock = new Mock<IPatientDocumentRepository> ();
            var patientDocumentFactory = new PatientDocumentFactory (
                patientDocumentRepositoryMock.Object, hashingUtility.Object );
            var patient = new Mock<Patient> ();

            var patientDocument = new Mock<PatientDocument> ();
            patientDocument.Setup ( p => p.Patient ).Returns ( patient.Object );

            patientDocumentFactory.DestroyPatientDocument ( patientDocument.Object );
        }
        public void DestroyPatientDocument_GivenPatientDocument_MadeTransient()
        {
            bool madeTransient = true;
            var hashingUtility = new Mock<IHashingUtility>();
            hashingUtility.Setup(m => m.ComputeHash(It.IsAny<byte[]>())).Returns("XXXXXXXXXXX");

            var patientDocumentRepositoryMock = new Mock<IPatientDocumentRepository> ();
            patientDocumentRepositoryMock
                .Setup ( p => p.MakeTransient ( It.IsAny<PatientDocument> () ) )
                .Callback ( () => madeTransient = true );
            var patientDocumentFactory = new PatientDocumentFactory (
                patientDocumentRepositoryMock.Object, hashingUtility.Object );
            var patient = new Mock<Patient> ();

            var patientDocument = new Mock<PatientDocument> ();
            patientDocument.Setup ( p => p.Patient ).Returns ( patient.Object );

            patientDocumentFactory.DestroyPatientDocument ( patientDocument.Object );

            Assert.IsTrue ( madeTransient );
        }
        public void CreatePatientDocument_NullPatientDocumentType_ThrowsException()
        {
            var bytes = new byte[] { 0, 0, 0 };
            var hashingUtility = new Mock<IHashingUtility>();
            hashingUtility.Setup(m => m.ComputeHash(It.IsAny<byte[]>())).Returns("XXXXXXXXXXX");

            var patientDocumentRepositoryMock = new Mock<IPatientDocumentRepository> ();
            var patientDocumentFactory = new PatientDocumentFactory (
                patientDocumentRepositoryMock.Object, hashingUtility.Object );
            var patient = new Mock<Patient> ();

            patientDocumentFactory.CreatePatientDocument (
                patient.Object,
                null,
                bytes,
                "filename");
        }