Beispiel #1
0
        public void Set_ValuesReturnFalse_ReturnIsFalse()
        {
            // Arrange
            var valuesMock = new Mock <IValuesRepository>();

            valuesMock
            .Setup(x => x.Set(It.IsAny <Value>()))
            .Returns(false);

            var keyIdPairsMock = new Mock <IKeyIdPairsRepository>();

            keyIdPairsMock
            .Setup(x => x.Set(It.IsAny <string>(), It.IsAny <int>()))
            .Returns(true);

            var personalBackend = new PersonalBackendModel(
                valuesMock.Object,
                keyIdPairsMock.Object);

            // Act
            var result = personalBackend.TestSetMethod <object>("key", "value");

            // Assert
            Assert.IsFalse(result);

            valuesMock.Verify(x =>
                              x.Set(It.IsAny <Value>()),
                              Times.Once());

            keyIdPairsMock.Verify(x =>
                                  x.Set(It.IsAny <string>(), It.IsAny <int>()),
                                  Times.Never());
        }
Beispiel #2
0
        public void Get_ValuesReturnNull_ReturnIsNull()
        {
            // Arrange
            var valuesMock = new Mock <IValuesRepository>();

            valuesMock
            .Setup(x => x.Get(It.IsAny <int>()))
            .Returns <Value>(null);

            int keyIdPairsResult;
            var keyIdPairsMock = new Mock <IKeyIdPairsRepository>();

            keyIdPairsMock
            .Setup(x => x.TryGet(It.IsAny <string>(), out keyIdPairsResult))
            .Returns(true);

            var personalBackend = new PersonalBackendModel(
                valuesMock.Object,
                keyIdPairsMock.Object);

            // Act
            var result = personalBackend.TestGetMethod <object>("key");

            // Assert
            Assert.IsNull(result);

            keyIdPairsMock.Verify(x =>
                                  x.TryGet(It.IsAny <string>(), out keyIdPairsResult),
                                  Times.Once());

            valuesMock.Verify(x =>
                              x.Get(It.IsAny <int>()),
                              Times.Once());
        }
Beispiel #3
0
        public void Set_KeyIsLong_ReturnIsFalse()
        {
            // Arrange
            var valuesMock      = new Mock <IValuesRepository>();
            var keyIdPairsMock  = new Mock <IKeyIdPairsRepository>();
            var personalBackend = new PersonalBackendModel(
                valuesMock.Object,
                keyIdPairsMock.Object);

            // Act
            var result = personalBackend.TestSetMethod <object>(new string('k', 200), null);

            // Assert
            Assert.IsFalse(result);
        }
Beispiel #4
0
        public void Get_KeyIsNull_ReturnIsNull()
        {
            // Arrange
            var valuesMock      = new Mock <IValuesRepository>();
            var keyIdPairsMock  = new Mock <IKeyIdPairsRepository>();
            var personalBackend = new PersonalBackendModel(
                valuesMock.Object,
                keyIdPairsMock.Object);

            // Act
            var result = personalBackend.TestGetMethod <object>(null);

            // Assert
            Assert.IsNull(result);
        }