Exemplo n.º 1
0
        /// <summary>
        /// Modify DiaryNote
        /// </summary>
        public void Modify(DiaryNote diaryNote)
        {
            const string SQL_TO_MODIFY =
                @"UPDATE Business.DiaryNote 
                  SET 
                      Content = @Content, 
                      UpdatedByUserId = @UpdatedByUserId
                  WHERE
                      Id = @Id; ";

            var parameters = new List<SqlParameter>
            {
                DbHelper.CreateParameter(DiaryNoteMapper.Parameters.Id, diaryNote.Id),
                DbHelper.CreateParameter(DiaryNoteMapper.Parameters.Content, diaryNote.Content)
            };

            // Add auditing parameters
            AuditFieldsHelper.PopulateAuditFields(parameters);

            // Execute the query
            var rowsAffected = DbHelper.ExecuteNonQueryCommand(SQL_TO_MODIFY, parameters: parameters);

            // Check if the update was successful
            if (rowsAffected == 0)
            {
                throw new ExpectedResultException(ErrorFactory.CreateAndLogError(Errors.SRVEX30027,
                                                                             "DiaryNoteDao.Modify",
                                                                             additionalDescriptionParameters:
                                                                                 (new object[] {diaryNote.GetType().Name, diaryNote.Id }),
                                                                             arguments:
                                                                                 new object[] {diaryNote.GetType().Name, diaryNote.Id }));
            }
        }
            public void GetDiaryNoteWithExpectedResult()
            {
                // Arrange
                const long BUSINESS_ID = 1;
                const int DIARY_NOTE_ID = 1;
                var stubBusinessManager = MockRepository.GenerateStub<IBusinessManager>();

                var diaryNote = new DiaryNote
                {
                    Id = DIARY_NOTE_ID,
                    BusinessId = BUSINESS_ID,
                    Content = "Diary Note",
                    Date = DateTime.Today
                };

                stubBusinessManager.Stub(x => x.GetDiaryNote(BUSINESS_ID, DIARY_NOTE_ID)).Return(diaryNote);

                PropertyManagementSystemService.BusinessManager = stubBusinessManager;

                // Stub the BusinessCache to be used by our service method
                CacheHelper.StubBusinessCacheSingleBusiness(BUSINESS_ID);

                // invalidate the cache so we make sure our business is loaded into the cache
                Cache.Business.Invalidate();

                // Act
                var diaryNoteDto = PropertyManagementSystemService.GetDiaryNote(BUSINESS_ID, DIARY_NOTE_ID);

                // Assert
                Assert.IsNotNull(diaryNoteDto, "Diary note information retrieved is null.");
                Assert.IsTrue(diaryNoteDto.Id != default(int), "Id attribute is not present on Diary Note object.");
                Assert.AreEqual(diaryNoteDto.BusinessId, diaryNote.BusinessId, "Business Id attribute doesnt match on Diary Note object");
                Assert.AreEqual(diaryNoteDto.Date, diaryNote.Date, "Date attribute doesnt match on Diary Note object");
                Assert.AreEqual(diaryNoteDto.Content, diaryNote.Content, "Content attribute doesnt match on Diary Note object");

                //cleanup
                CacheHelper.ReAssignBusinessDaoToBusinessCache();
            }
Exemplo n.º 3
0
            public void CreateNote()
            {
                // Arrange
                var stubDiaryNoteDao = MockRepository.GenerateStub<IDiaryNoteDao>();
                businessManager.DiaryNoteDao = stubDiaryNoteDao;

                var diaryNote = new DiaryNote
                {
                    BusinessId = 1,
                    Content = "Really Cool Note",
                    Date = DateTime.Today
                };

                stubDiaryNoteDao.Stub(b => b.Create(diaryNote)).WhenCalled(delegate { diaryNote.Id = 1; });

                // Act   
                businessManager.CreateDiaryNote(diaryNote);

                // Assert
                Assert.AreNotEqual(diaryNote.Id, default(int), "The diary note Id was not set correctly");
            }
Exemplo n.º 4
0
        /// <summary>
        /// Create DiaryNote
        /// </summary>
        public void Create(DiaryNote diaryNote)
        {
            const string SQL_TO_INSERT =
                @"INSERT INTO Business.DiaryNote
                            (BusinessId, 
                             Content, 
                             Date,
                             UpdatedByUserId) 
                         VALUES 
                            (@BusinessId, 
                             @Content,
                             @Date,
                             @UpdatedByUserId); 
                SET @Id = SCOPE_IDENTITY();";

            var parameters = new List<SqlParameter>
            {
                DbHelper.CreateParameter(DiaryNoteMapper.Parameters.BusinessId, diaryNote.BusinessId),
                DbHelper.CreateParameter(DiaryNoteMapper.Parameters.Content, diaryNote.Content),
                DbHelper.CreateParameter(DiaryNoteMapper.Parameters.Date, diaryNote.Date)
            };

            // Add auditing parameters
            AuditFieldsHelper.PopulateAuditFields(parameters);

            SqlParameter outputKey;
            parameters.Add(outputKey = DbHelper.CreateParameterOut<int>(DiaryNoteMapper.Parameters.Id, SqlDbType.Int));

            // Execute the query
            DbHelper.ExecuteNonQueryCommand(SQL_TO_INSERT, parameters: parameters);

            // Make sure the record was created
            if (outputKey.Value == DBNull.Value)
            {
                throw new PrimaryKeyNotSetException(ErrorFactory.CreateAndLogError(Errors.SRVEX30022, "DiaryNoteDao.Create",
                    additionalDescriptionParameters: (new object[] { diaryNote.BusinessId })));
            }

            diaryNote.Id = DbHelper.ParameterValue<int>(outputKey);
        }
Exemplo n.º 5
0
            public void ModifyDiaryNote()
            {
                // Arrange
                var stubDiaryNoteDao = MockRepository.GenerateStub<IDiaryNoteDao>();
                businessManager.DiaryNoteDao = stubDiaryNoteDao;

                stubDiaryNoteDao.Expect(x => x.Modify(Arg<DiaryNote>.Is.Anything));

                var updatedNote = new DiaryNote { Id = 1, BusinessId = 1, Content = "Notes", Date = DateTime.Today };

                // Act
                businessManager.ModifyDiaryNote(updatedNote);

                // Assert
                stubDiaryNoteDao.VerifyAllExpectations();
            }
Exemplo n.º 6
0
            public void ModifyDiaryNoteWithBlankContentRemovesNote()
            {
                // Arrange
                const int DIARY_NOTE_ID = 1;

                var stubDiaryNoteDao = MockRepository.GenerateStub<IDiaryNoteDao>();
                businessManager.DiaryNoteDao = stubDiaryNoteDao;

                stubDiaryNoteDao.Expect(x => x.Remove(Arg<int>.Is.Equal(DIARY_NOTE_ID))).Return(true);

                var updatedNote = new DiaryNote { Id = DIARY_NOTE_ID, BusinessId = 1, Content = string.Empty, Date = DateTime.Today };

                // Act
                businessManager.ModifyDiaryNote(updatedNote);

                // Assert
                stubDiaryNoteDao.VerifyAllExpectations();
            }
Exemplo n.º 7
0
            public void GetDiaryNoteByBusiness()
            {
                // Arrange
                const long BUSINESS_ID = 1;
                const int DIARY_NOTE_ID = 1;

                var stubDiaryNoteDao = MockRepository.GenerateStub<IDiaryNoteDao>();

                var diaryNoteReturnedByDao = new DiaryNote
                {
                    BusinessId = 1,
                    Content = "Really Cool Note",
                    Date = DateTime.Today
                };

                stubDiaryNoteDao.Stub(r => r.GetByKey(BUSINESS_ID, DIARY_NOTE_ID)).Return(diaryNoteReturnedByDao);

                businessManager.DiaryNoteDao = stubDiaryNoteDao;

                // Act
                var diaryNoteReturnedByManager = businessManager.GetDiaryNote(BUSINESS_ID, DIARY_NOTE_ID);

                // Assert
                Assert.IsNotNull(diaryNoteReturnedByManager, "Diary Note retrieved is null.");
                Assert.AreEqual(diaryNoteReturnedByDao, diaryNoteReturnedByManager, "Diary Note returned is not correct.");
            }
Exemplo n.º 8
0
 /// <summary>
 /// Create DiaryNote
 /// </summary>
 public void CreateDiaryNote(DiaryNote diaryNote)
 {
     diaryNoteDao.Create(diaryNote);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Modify DiaryNote
        /// </summary>
        public bool ModifyDiaryNote(DiaryNote diaryNote)
        {
            if (!string.IsNullOrEmpty(diaryNote.Content))
            {
                diaryNoteDao.Modify(diaryNote);
            }
            else
            {
                diaryNoteDao.Remove(diaryNote.Id);
            }

            return true;
        }
Exemplo n.º 10
0
            public void CreateDiaryNoteExpectedResult()
            {
                // Arrange
                using (new TestDataHelper(GetTestQuery(TestQuery.PopulateDiaryNoteTestData), GetTestQuery(TestQuery.CleanupUnitTestData)))
                {
                    // Arrange
                    const long BUSINESS_ID = 1;

                    var diaryNote = new DiaryNote
                                        {
                                            BusinessId = BUSINESS_ID,
                                            Content = "Modified Content",
                                            Date = DateTime.Today
                                        };

                    DateTime beforeDateTime = DateTime.UtcNow.AddSeconds(-10);

                    // Act
                    diaryNoteDao.Create(diaryNote);

                    DateTime afterDateTime = DateTime.UtcNow.AddSeconds(10);

                    Assert.AreNotEqual(diaryNote.Id, default(int), "Diary note Id is not valid");

                    var diaryNoteCreated = diaryNoteDao.GetByKey(BUSINESS_ID, diaryNote.Id);

                    // Assert
                    Assert.IsNotNull(diaryNoteCreated, "Diary note information retrieved is null.");
                    Assert.AreEqual(diaryNote.Content, diaryNoteCreated.Content, "Diary note content has not been updated");
                    Assert.AreEqual(diaryNote.Date, diaryNoteCreated.Date, "Diary note date has not been updated");
                    Assert.IsTrue(diaryNoteCreated.UpdatedByUserId == TEST_USER_ID, "UpdatedByUserId is not correct on Diary note object");
                    Assert.IsTrue(diaryNoteCreated.UpdatedDateTime >= beforeDateTime && diaryNote.UpdatedDateTime <= afterDateTime,"UpdatedDateTime is not correct on Diary note object");
                }
            }
Exemplo n.º 11
0
            public void ModifyNonExistingDiaryNoteThrowsExpectedResultException()
            {
                var diaryNote = new DiaryNote
                                    {
                                        Id = 999,
                                        BusinessId = 999,
                                        Content = "Modified Content",
                                        Date = DateTime.Today
                                    };

                try
                {
                    // Modify diary note record
                    diaryNoteDao.Modify(diaryNote);

                    Assert.Fail("An exception of type ExpectedResultException should have been thrown");
                }
                catch (ExpectedResultException ex)
                {
                    Assert.AreEqual(ex.Code, "SRVEX30027", "Exception code returned is incorrect.");
                }
            }