コード例 #1
0
            public void EditCloseOutWithExpectedResult()
            {
                // Arrange
                const long BUSINESS_ID = -1;

                var closeoutDto = new CloseoutDto
                {
                    BusinessId = BUSINESS_ID,
                    Description = "",
                    StartDate = DateTime.Now,
                    EndDate = DateTime.Now.AddDays(1),
                    RoomId = 1
                };

                stubCloseOutManager.Expect(c => c.Modify(Arg<Closeout>.Is.Anything));

                // 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
                bool isEdited = PropertyManagementSystemService.EditCloseout(BUSINESS_ID, closeoutDto);

                // Assert
                Assert.IsTrue(isEdited, "The updated CloseOut is not updated correctly");
                stubCloseOutManager.VerifyAllExpectations();

                // Reassign the Dao on the cache to discard the stub assigned on the StubBusinessCacheSingleBusiness method
                CacheHelper.ReAssignBusinessDaoToBusinessCache();
            }
コード例 #2
0
            public void EditCloseOutWithInvalidBusiness()
            {
                // Arrange
                const long BUSINESS_ID = -10;

                var closeoutDto = new CloseoutDto
                {
                    BusinessId = BUSINESS_ID,
                    Description = "",
                    StartDate = DateTime.Now,
                    EndDate = DateTime.Now.AddDays(1),
                    RoomId = 1
                };

                try
                {
                    // Act
                    PropertyManagementSystemService.EditCloseout(BUSINESS_ID, closeoutDto);

                    // Assert
                    Assert.Fail("An exception SRVEX30001 of type ValidationException should have been thrown");
                }
                catch (ValidationException ex)
                {
                    // Assert
                    Assert.AreEqual("SRVEX30001", ex.Code,
                                    "The Validation exception is not returning the right error code");
                }
            }
コード例 #3
0
            public void EditCloseOutWithMissMatchBusiness()
            {
                // Arrange
                const long MISMATCHED_BUSINESS_ID = 5;

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

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

                var closeoutDto = new CloseoutDto
                {
                    Description = "",
                    StartDate = DateTime.Now,
                    EndDate = DateTime.Now.AddDays(1),
                    RoomId = 1
                };

                try
                {
                    // Act
                    PropertyManagementSystemService.EditCloseout(MISMATCHED_BUSINESS_ID, closeoutDto);

                    // Assert
                    Assert.Fail("An exception SRVEX30000 of type ValidationException should have been thrown");
                }
                catch (ValidationException ex)
                {
                    // Assert
                    Assert.AreEqual("SRVEX30000", ex.Code,
                                    "The Validation exception is not returning the right error code");
                }
                finally
                {
                    // Reassign the Dao on the cache to discard the stub assigned on the StubBusinessCacheSingleBusiness method
                    CacheHelper.ReAssignBusinessDaoToBusinessCache();

                }
            }
コード例 #4
0
            public void CreateCloseoutWithInvalidBusinessThrowsException()
            {
                // Arrange

                // business that we know will never exist in cache
                const long BUSINESS_ID = -100;

                var closeoutDto = new CloseoutDto
                {
                    BusinessId = BUSINESS_ID,
                    RoomId = 1,
                    StartDate = DateTime.UtcNow,
                    EndDate = DateTime.UtcNow.AddDays(1),
                    Description = "Test Closeout"
                };

                try
                {
                    // Act
                    PropertyManagementSystemService.CreateCloseout(BUSINESS_ID, closeoutDto);

                    // Assert
                    Assert.Fail("An exception SRVEX30001 of type ValidationException should have been thrown");
                }
                catch (ValidationException ex)
                {
                    // Assert
                    Assert.AreEqual("SRVEX30001", ex.Code,
                                    "The Validation exception is not returning the right error code");
                }
            }
コード例 #5
0
            public void CreateCloseoutWithExpectedResult()
            {
                // Arrange
                const long BUSINESS_ID = 1;
                var closeoutDto = new CloseoutDto
                {
                    BusinessId = BUSINESS_ID,
                    RoomId = 1,
                    StartDate = DateTime.UtcNow,
                    EndDate = DateTime.UtcNow.AddDays(1),
                    Description = "Test Closeout"
                };

                mockCloseoutManager.Expect(x => x.CreateCloseout(Arg<Closeout>.Is.Anything)).WhenCalled(
                    x => ((Closeout)x.Arguments[0]).Id = 1);

                // 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
                CloseoutDto closeoutCreated = PropertyManagementSystemService.CreateCloseout(BUSINESS_ID, closeoutDto);

                // Assert 
                Assert.IsNotNull(closeoutCreated, "Closeout was not created successfully.");
                Assert.IsNotNull(closeoutCreated.Id, "Id attribute is not populated.");
                mockCloseoutManager.VerifyAllExpectations();

                // Reassign the Dao on the cache to discard the stub assigned on the StubBusinessCacheSingleBusiness method
                CacheHelper.ReAssignBusinessDaoToBusinessCache();
            }
コード例 #6
0
        public bool EditCloseout(long businessId, CloseoutDto closeoutDto)
        {
            CheckAccessRights(businessId);

            // Validate if the business exists
            if (Cache.Business.TryGetValue(businessId) == null)
            {
                throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30001, "PropertyManagementSystemService.EditCloseout",
                    additionalDescriptionParameters: (new object[] { businessId })));
            }

            if (businessId != closeoutDto.BusinessId)
            {
                throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30000, "PropertyManagementSystemService.EditCloseout",
                    additionalDescriptionParameters: (new object[] { businessId, closeoutDto.BusinessId }), arguments: new object[] { businessId, closeoutDto }));
            }

            Closeout closeout = Mapper.Map<Closeout>(closeoutDto);

            closeoutManager.Modify(closeout);

            return true;
        }