public void CreateEquipment_VAP_ROZFailedScednario_ValidateUserAbleReceivesError()
        {
            using (ShimsContext.Create())
            {
                // Given a user that has permission to create new equpment
                ShimCurrentUser.AsUserDto = () => new SIMPLTestContext().GetFakeUserDtoObject();

                // And the new equipemnt to be created is a video access point
                var createEquipmentModel = new CreateEquipmentModel
                {
                    SerialNumber = "A0B1C2D3E4F5",
                    LocationID = "HEADEND 04 INVENTORY",
                    Status = "IGNORE",
                    SelectedModel = "VEN401",
                    UnitAddress = "A0:B1:C2:D3:E4:F5",
                    Category = EquipmentCategoryDto.VideoAccessPoint.ToString()
                };

                // When creating new vap but it failed during ROZ equpment creation
                const string rozErrorMessage = "error message";
                ShimRosettianClient.AllInstances.CreateEquipmentEquipmentDtoUserDto =
                    (myTestClient, myEquipmentCriteria, myUserDto) => { throw new Exception(rozErrorMessage); };

                var searchController = DependencyResolver.Current.GetService<SearchController>();
                var actionResponse = searchController.CreateEquipment(createEquipmentModel) as JsonResult;

                // Then the user receives a response
                Assert.IsNotNull(actionResponse, "CreateEquipment method returned null");

                // And the response is an error
                Assert.IsNotNull(actionResponse.Data, "CreateEquipment response data is null");
                var jss = new JavaScriptSerializer();
                var expectedResult = new
                {
                    status = "error",
                    errorMessage = rozErrorMessage
                }.ToJSON();
                Assert.AreEqual(jss.Serialize(expectedResult), jss.Serialize(actionResponse.Data.ToJSON()));
            }
        }
        public void User_attempts_to_create_new_equipment_with_correct_data_and_an_non_Rosettian_error_is_returned()
        {
            using (ShimsContext.Create())
            {
                //Arrange
                // Given a user that has permission to create new equpment
                ShimCurrentUser.AsUserDto = () => new SIMPLTestContext().GetFakeUserDtoObject();

                // And the new equipemnt to be created is a video access point
                var createEquipmentModel = new CreateEquipmentModel
                {
                    SerialNumber = "A0B1C2D3E4F5",
                    LocationID = "HEADEND 04 INVENTORY",
                    Status = "IGNORE",
                    SelectedModel = "VEN401",
                    UnitAddress = "A0:B1:C2:D3:E4:F5",
                    Category = EquipmentCategoryDto.VideoAccessPoint.ToString()
                };

                // When creating new vap with the valid info
                ShimRosettianClient.AllInstances.CreateEquipmentEquipmentDtoUserDto =
                    (myTestClient, myEquipmentCriteria, myUserDto) => { };

                //Create a non-Fault exception
                const string exceptionMessage = "This is my argument exception";
                ShimEquipmentExtension.MapToDeviceCreateEquipmentModel =
                    delegate { throw new ArgumentException(exceptionMessage); };

                //Act
                var searchController = DependencyResolver.Current.GetService<SearchController>();
                var actionResponse = searchController.CreateEquipment(createEquipmentModel) as JsonResult;

                //Assert
                // Then the user receives a response
                Assert.IsNotNull(actionResponse, "CreateEquipment method returned null");

                //Data is returned
                Assert.IsNotNull(actionResponse.Data, "CreateEquipment response data is null");
                var jss = new JavaScriptSerializer();

                //The response is expected to be an error
                var expectedResult = new
                {
                    status = "error",
                    errorMessage = exceptionMessage
                }.ToJSON();
                Assert.AreEqual(jss.Serialize(expectedResult), jss.Serialize(actionResponse.Data.ToJSON()));
            }
        }
        public void User_attempts_to_create_new_equipment_with_correct_data_and_a_Rosettian_error_is_returned()
        {
            using (ShimsContext.Create())
            {
                //Arrange
                // Given a user that has permission to create new equpment
                ShimCurrentUser.AsUserDto = () => new SIMPLTestContext().GetFakeUserDtoObject();

                // And the new equipemnt to be created is a video access point
                var createEquipmentModel = new CreateEquipmentModel
                {
                    SerialNumber = "A0B1C2D3E4F5",
                    LocationID = "HEADEND 04 INVENTORY",
                    Status = "IGNORE",
                    SelectedModel = "VEN401",
                    UnitAddress = "A0:B1:C2:D3:E4:F5",
                    Category = EquipmentCategoryDto.VideoAccessPoint.ToString()
                };

                //This is for creating a Fault exception
                const string expectedErrorMessage = "This is a fault exception message";
                var faultDetail = new ValidationDetailDto()
                {
                    Message = expectedErrorMessage
                };

                var faultDetails = new List<ValidationDetailDto> { faultDetail };

                var validationFault = new ValidationFaultDto()
                {
                    Details = faultDetails
                };

                var fault = new FaultException<ValidationFaultDto>(validationFault);

                //Have Controller CreateEquipment method throw the fault when called
                ShimRosettianClient.AllInstances.CreateEquipmentEquipmentDtoUserDto = delegate { throw fault; };

                //Act
                var searchController = DependencyResolver.Current.GetService<SearchController>();
                var actionResponse = searchController.CreateEquipment(createEquipmentModel) as JsonResult;

                //Assert
                // Then the user receives a response
                Assert.IsNotNull(actionResponse, "CreateEquipment method returned null");

                //Data was returned
                Assert.IsNotNull(actionResponse.Data, "CreateEquipment response data is null");
                var jss = new JavaScriptSerializer();

                //The data is expected to be an error
                var expectedResult = new
                {
                    status = "error",
                    errorMessage = "This is a fault exception message"
                }.ToJSON();
                Assert.AreEqual(jss.Serialize(expectedResult), jss.Serialize(actionResponse.Data.ToJSON()));
            }
        }
        public void CreateEquipment_VAP_ValidateUserAbleToCreateVAP()
        {
            using (ShimsContext.Create())
            {
                // Given a user that has permission to create new equpment
                ShimCurrentUser.AsUserDto = () => new SIMPLTestContext().GetFakeUserDtoObject();

                // And the new equipemnt to be created is a video access point
                var createEquipmentModel = new CreateEquipmentModel
                {
                    SerialNumber = "A0B1C2D3E4F5",
                    LocationID = "HEADEND 04 INVENTORY",
                    Status = "IGNORE",
                    SelectedModel = "VEN401",
                    UnitAddress = "A0:B1:C2:D3:E4:F5",
                    Category = EquipmentCategoryDto.VideoAccessPoint.ToString()
                };

                // When creating new vap with the valid info
                ShimRosettianClient.AllInstances.CreateEquipmentEquipmentDtoUserDto =
                    (myTestClient, myEquipmentCriteria, myUserDto) => { };

                var searchController = DependencyResolver.Current.GetService<SearchController>();
                var actionResponse = searchController.CreateEquipment(createEquipmentModel) as JsonResult;

                // Then the user receives a response
                Assert.IsNotNull(actionResponse, "CreateEquipment method returned null");

                // And the response is successful
                // And the serial number created matches the requested serial number
                Assert.IsNotNull(actionResponse.Data, "CreateEquipment response data is null");
                var jss = new JavaScriptSerializer();
                var expectedResult = new
                {
                    status = "valid",
                    newDeviceID = createEquipmentModel.SerialNumber
                }.ToJSON();
                Assert.AreEqual(jss.Serialize(expectedResult), jss.Serialize(actionResponse.Data.ToJSON()));
            }
        }