예제 #1
0
            public async void Should_return_BadRequest_when_model_is_null()
            {
                //Arrange
                UserUpdate user             = null;
                var        userId           = 1;
                var        returnExistValue = true;
                var        key             = "Me_StatusCode_400_BadRequest";
                var        localizedString = new LocalizedString(key, "Bad Request");

                LocalizerMock
                .Setup(_ => _[key])
                .Returns(localizedString);

                // Service
                UserServiceMock.Setup(x => x.IsExistAsync(userId)).ReturnsAsync(returnExistValue);

                // set header values
                ControllerUnderTest.ControllerContext.HttpContext.Request.Headers.Add("id", userId.ToString());

                //Act
                var result = await ControllerUnderTest.Update(user);

                //Assert
                Assert.IsType <BadRequestObjectResult>(result);
            }
예제 #2
0
            public async void Should_return_NotFound_when_phone_is_Invalid()
            {
                // Arrange
                var      invalidUserId   = 0;
                var      expirationDays  = "2";
                string   key             = "User_StatusCode_404_NotFound";
                var      localizedString = new LocalizedString(key, "Not Found");
                Contacts contact         = new Contacts()
                {
                    Phone = new Phone
                    {
                        CountryCode = "123",
                        Number      = "7894561230"
                    }
                };

                ContactServiceMock.Setup(x => x.CheckValidUserByPhoneAsync(contact.Phone))
                .ReturnsAsync(invalidUserId);

                ConfigurationMock.Setup(x => x["PasswordConfig:OTPExpiryTime"])
                .Returns(expirationDays);

                LocalizerMock
                .Setup(_ => _[key]).Returns(localizedString);

                // Act
                var result = await ControllerUnderTest.ForgotPassword(contact);

                Assert.IsType <NotFoundObjectResult>(result);
            }
            public async void Should_return_NoContent_when_a_addressId_is_Invalid()
            {
                // Arrange
                var     userId = 1;
                var     unExistingAddressId = 55;
                Address address             = null;

                AddressServiceMock
                .Setup(x => x.ReadOneAsync(userId, unExistingAddressId)).ReturnsAsync(address);


                var key             = "Address_StatusCode_404_NotFound";
                var localizedString = new LocalizedString(key, "Not Found");

                LocalizerMock
                .Setup(_ => _[key])
                .Returns(localizedString);
                // Act

                var result = await ControllerUnderTest.GetUserAddress(userId, unExistingAddressId);

                // Assert

                Assert.IsType <NotFoundObjectResult>(result);
            }
예제 #4
0
            public async void Should_return_BadRequest_when_model_is_null()
            {
                // Arrange
                var key             = "User_StatusCode_400_BadRequest";
                var localizedString = new LocalizedString(key, "Bad Request");

                LocalizerMock
                .Setup(_ => _[key])
                .Returns(localizedString);

                // Act
                var result = await ControllerUnderTest.CreateUser(null);

                // Assert
                Assert.IsType <BadRequestObjectResult>(result);
            }
예제 #5
0
            public async void Should_return_BadRequest_when_contact_is_null()
            {
                // Arrange
                Contacts contact = new Contacts()
                {
                    Phone = null
                };
                string key             = "User_StatusCode_400_BadRequest";
                var    localizedString = new LocalizedString(key, "Bad Request");

                LocalizerMock
                .Setup(_ => _[key]).Returns(localizedString);

                // Assert
                var result = await ControllerUnderTest.ForgotPassword(contact);

                Assert.IsType <BadRequestObjectResult>(result);
            }
예제 #6
0
            public async void Should_return_NoFoundResult_when_Id_is_invalid()
            {
                //Arrange
                var unexistingUserId = 2;
                var user             = UserUpdate;
                var key             = "User_StatusCode_404_NotFound";
                var localizedString = new LocalizedString(key, "Not Found");

                LocalizerMock
                .Setup(_ => _[key])
                .Returns(localizedString);

                //Act
                var result = await ControllerUnderTest.Update(unexistingUserId, user);

                //Assert
                Assert.IsType <NotFoundObjectResult>(result);
            }
예제 #7
0
            public async void Should_return_BadRequestResult_when_Id_is_zero()
            {
                //Arrange
                var unexistingUserId = 0;
                var userData         = UserUpdate;
                var key             = "User_StatusCode_400_BadRequest";
                var localizedString = new LocalizedString(key, "Bad Request");

                LocalizerMock
                .Setup(_ => _[key])
                .Returns(localizedString);

                //Act
                var result = await ControllerUnderTest.Update(unexistingUserId, userData);

                //Assert
                Assert.IsType <BadRequestObjectResult>(result);
            }
예제 #8
0
            public async void Should_return_NotFoundResult_when_UserNotFoundException_is_thrown()
            {
                // Arrange
                var    unexistingUserId = 2;
                string key             = "User_StatusCode_404_NotFound";
                var    localizedString = new LocalizedString(key, "Not Found");

                UserServiceMock
                .Setup(x => x.ReadOneAsync(unexistingUserId))
                .ThrowsAsync(new Exception(unexistingUserId.ToString()));

                LocalizerMock
                .Setup(_ => _[key]).Returns(localizedString);

                // Act
                var result = await ControllerUnderTest.GetUser(unexistingUserId);

                // Assert
                Assert.IsType <NotFoundObjectResult>(result);
            }
예제 #9
0
            public async void Should_return_NotFoundResult_when_id_is_invalid()
            {
                // Arrange
                var unexistingUserId = 2;
                var key             = "User_StatusCode_404_NotFound";
                var localizedString = new LocalizedString(key, "Not Found");

                LocalizerMock
                .Setup(_ => _[key]).Returns(localizedString);

                UserServiceMock
                .Setup(o => o.RemoveAsync(unexistingUserId))
                .ThrowsAsync(new ArgumentException(unexistingUserId.ToString()));

                // Act
                var result = await ControllerUnderTest.Delete(unexistingUserId);

                // Assert
                Assert.IsType <NotFoundObjectResult>(result);
            }
            public async void Should_return_BadRequest_when_addressId_is_zero()
            {
                //Arrange
                var userId = 0;
                var unExistingAddressId = 0;
                var address             = AddressData;

                var key             = "Address_StatusCode_400_BadRequest";
                var localizedString = new LocalizedString(key, "Bad Request");

                LocalizerMock
                .Setup(_ => _[key])
                .Returns(localizedString);

                //Act
                var result = await ControllerUnderTest.UpdateUserAddress(userId, unExistingAddressId, address);

                //Assert
                Assert.IsType <BadRequestObjectResult>(result);
            }
            public async void Should_return_NotFoundRequest_when_addressId_is_invalid()
            {
                //Arrange
                var            userId      = 2;
                var            addressId   = 18;
                List <Address> addresses   = Addresses;
                var            addressData = AddressData;

                var key             = "Address_StatusCode_404_NotFound";
                var localizedString = new LocalizedString(key, "Not Found");

                LocalizerMock
                .Setup(_ => _[key])
                .Returns(localizedString);

                //Act
                var result = await ControllerUnderTest.UpdateUserAddress(userId, addressId, addressData);

                //Assert
                Assert.IsType <NotFoundObjectResult>(result);
            }
예제 #12
0
            public async void Should_return_NoFoundResult_when_Id_is_invalid()
            {
                //Arrange
                var unexistingUserId = 2;
                var user             = UserUpdate;
                var key             = "Me_StatusCode_404_NotFound";
                var localizedString = new LocalizedString(key, "Not Found");

                LocalizerMock
                .Setup(_ => _[key])
                .Returns(localizedString);

                // set header values

                ControllerUnderTest.ControllerContext.HttpContext.Request.Headers.Add("id", unexistingUserId.ToString());

                //Act
                var result = await ControllerUnderTest.Update(user);

                //Assert
                Assert.IsType <NotFoundObjectResult>(result);
            }
            public async void Should_return_BadResult_when_model_is_null()
            {
                List <Address> address          = null;
                var            userId           = 6;
                var            returnExistValue = true;
                var            key             = "Address_StatusCode_400_BadRequest";
                var            localizedString = new LocalizedString(key, "Bad Request");


                LocalizerMock
                .Setup(_ => _[key])
                .Returns(localizedString);

                // Service
                UserServiceMock.Setup(x => x.IsExistAsync(userId)).ReturnsAsync(returnExistValue);

                //Act
                var result = await ControllerUnderTest.Update(userId, address);

                //Assert
                Assert.IsType <BadRequestObjectResult>(result);
            }