Exemplo n.º 1
0
            public void CreateCloseoutWithExpectedResult()
            {
                // Arrange
                const long BUSINESS_ID = 1;
                var closeoutDto = new CloseoutDto
                {
                    BusinessId = BUSINESS_ID,
                    RoomId = 1,
                    StartDateUTC = DateTime.UtcNow,
                    EndDateUTC = DateTime.UtcNow.AddDays(1),
                    Description = "Test Closeout",
                    CreatedByUserId = Guid.NewGuid(),
                    CreatedDateTimeUTC = DateTime.UtcNow
                };

                var mockCloseoutManager = MockRepository.GenerateMock<ICloseoutManager>();
                mockCloseoutManager.Expect(x => x.CreateCloseout(Arg<Closeout>.Is.Anything)).WhenCalled(x => ((Closeout)x.Arguments[0]).Id = 1);
                limitedMobileService.CloseoutManager = mockCloseoutManager;
                limitedMobileService.FakeAuthenticationForDebugging = true;

                // 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 = limitedMobileService.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();
            }
Exemplo n.º 2
0
            public void EditCloseOutWithExpectedResult()
            {
                // Arrange
                const long BUSINESS_ID = 1;

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

                var stubCloseOutManager = MockRepository.GenerateMock<ICloseoutManager>();
                limitedMobileService.CloseoutManager = stubCloseOutManager;
                limitedMobileService.FakeAuthenticationForDebugging = true;

                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 = limitedMobileService.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();
            }
Exemplo n.º 3
0
            public void EditCloseOutWithInvalidBusiness()
            {
                // Arrange
                const long BUSINESS_ID = -1;

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

                try
                {
                    // Act
                    limitedMobileService.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");
                }
            }
Exemplo n.º 4
0
            public void EditCloseOutWithMisMatchBusiness()
            {
                // 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 = "",
                    StartDateUTC = DateTime.Now,
                    EndDateUTC = DateTime.Now.AddDays(1),
                    RoomId = 1
                };

                try
                {
                    // Act
                    limitedMobileService.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();
                    
                }
            }
Exemplo n.º 5
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,
                    StartDateUTC = DateTime.UtcNow,
                    EndDateUTC = DateTime.UtcNow.AddDays(1),
                    Description = "Test Closeout"
                };

                try
                {
                    // Act
                    limitedMobileService.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");
                }
            }
 ///<summary>
 /// Converts CloseoutDto to Closeout
 ///</summary>
 ///<param name="closeoutDto">CloseoutDto object to convert</param>
 ///<returns>Closeout entity object</returns>
 public static Closeout ConvertCloseoutDtoToCloseout(CloseoutDto closeoutDto)
 {
     return new Closeout
     {
         BusinessId = closeoutDto.BusinessId,
         Description = closeoutDto.Description,
         EndDate = closeoutDto.EndDateUTC,
         StartDate = closeoutDto.StartDateUTC,
         Id = closeoutDto.Id,
         RoomId = closeoutDto.RoomId,
         CreatedByUserId = closeoutDto.CreatedByUserId,
         CreatedDateTimeUTC = closeoutDto.CreatedDateTimeUTC
     };
 }