Exemplo n.º 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());
        }
Exemplo n.º 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());
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }