Esempio n. 1
0
        public async Task AddUserAsync_ExpectedResult()
        {
            var fixture        = new Fixture();
            var repoMock       = new Mock <IFortRepository>();
            var addUserRequest = fixture.Create <AddUserRequest>();

            repoMock.Setup(c => c.AddUserAsync(addUserRequest)).ReturnsAsync(1);
            var serviceObject = new FortService(repoMock.Object);
            var actualResult  = await serviceObject.AddUserAsync(addUserRequest);

            Assert.Equal(1, actualResult);
        }
Esempio n. 2
0
        public async Task AddUserAsync_FailedResult()
        {
            // Fixture are used to create a fixed environment in which tests are run so that results are repeatable.
            var fixture = new Fixture();
            //Mock object that will bypass the checking function
            var repoMock = new Mock <IFortRepository>();
            // This code is used to generate a random user details which all the properties which are there in the Class AddUserRequest.
            var addUserRequest = fixture.Create <AddUserRequest>();

            //repoMock.Setup is used to get the reponse from the AddUserAsync without calling to a DB (FortRepository), in this ReturnsAsync is the return value from this method.
            repoMock.Setup(c => c.AddUserAsync(addUserRequest)).ReturnsAsync(0);
            var serviceObject = new FortService(repoMock.Object);
            //This is used for calling AddUserAsync method in FortService class but here we'll get the response what we've intiliaze in repoMock.Setup
            var actualResult = await serviceObject.AddUserAsync(addUserRequest);

            //It will going to compare the values
            Assert.Equal(0, actualResult);
        }
Esempio n. 3
0
        public async Task AddUserAsync_WhenEmailIsNull_ThrowsException()
        {
            var fixture        = new Fixture();
            var repoMock       = new Mock <IFortRepository>();
            var addUserRequest = fixture.Build <AddUserRequest>()
                                 .Without(c => c.Email)
                                 .Create();
            var serviceObject = new FortService(repoMock.Object);
            var exception     = await Assert.ThrowsAsync <ArgumentNullException>(() => serviceObject.AddUserAsync(addUserRequest));

            Assert.Equal(nameof(addUserRequest.Email), exception.ParamName);
            repoMock.VerifyNoOtherCalls();
        }